TGeoTabManager.cxx

Go to the documentation of this file.
00001 // @(#):$Id: TGeoTabManager.cxx 36535 2010-11-08 14:41:54Z agheata $
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 //  TGeoTabManager  - manager for all editor tabs.                                                    //
00014 //                                                                      
00015 //  TGeoTreeDialog  - Base class for dialog frames for selecting objects 
00016 // with a tree hierarchy. Specific implementations are:
00017 //     TGeoVolumeDialog -  Special tree dialog class for selecting volumes.
00018 //     TGeoShapeDialog  -  Special tree dialog class for selecting shapes. 
00019 //     TGeoMediumDialog -  Special tree dialog class for selecting media.
00020 //     TGeoMaterialDialog - Special tree dialog class for selecting materials.
00021 //     TGeoMatrixDialog -  Special tree dialog class for selecting matrices.                   
00022 //  TGeoTransientPanel - Special transient tab holding TGeo editors.
00023 //______________________________________________________________________________
00024 
00025 #include "TROOT.h"
00026 #include "TClass.h"
00027 #include "TVirtualPad.h"
00028 #include "TGeoGedFrame.h"
00029 #include "TGTab.h"
00030 #include "TGLabel.h"
00031 #include "TGComboBox.h"
00032 #include "TGListBox.h"
00033 #include "TGListTree.h"
00034 #include "TGTextEntry.h"
00035 #include "TGCanvas.h"
00036 #include "TGMimeTypes.h"
00037 
00038 #include "TGeoManager.h"
00039 #include "TGeoShape.h"
00040 #include "TGeoVolume.h"
00041 #include "TGeoMedium.h"
00042 #include "TGeoMaterial.h"
00043 #include "TGeoMatrix.h"
00044 
00045 #include "TGedEditor.h"
00046 #include "TGeoTabManager.h"
00047 
00048 TMap TGeoTabManager::fgEditorToMgrMap;
00049 
00050 ClassImp(TGeoTabManager)
00051 
00052 //______________________________________________________________________________
00053 TGeoTabManager::TGeoTabManager(TGedEditor *ged)
00054 {
00055 // Ctor.
00056    fGedEditor = ged;
00057    fPad = ged->GetPad();
00058    fTab = ged->GetTab();
00059    fVolume = 0;
00060    fShapePanel = 0;
00061    fMediumPanel = 0;
00062    fMaterialPanel = 0;
00063    fMatrixPanel = 0;
00064    fVolumeTab = 0;
00065    fgEditorToMgrMap.Add(ged, this);
00066 }   
00067 
00068 //______________________________________________________________________________
00069 TGeoTabManager::~TGeoTabManager()
00070 {
00071 // Dtor.
00072    fgEditorToMgrMap.Remove(fGedEditor);
00073    if (fShapePanel) delete fShapePanel;
00074    if (fMaterialPanel) delete fMaterialPanel;
00075    if (fMatrixPanel) delete fMatrixPanel;
00076    if (fMediumPanel) delete fMediumPanel;
00077 }
00078 
00079 //______________________________________________________________________________
00080 void TGeoTabManager::Cleanup(TGCompositeFrame *frame)
00081 {
00082 // Static method to cleanup hirarchically all daughters of a composite frame.
00083 // Does not remove the frame itself.
00084    TGFrameElement *el;
00085    TList *list = frame->GetList();
00086    Int_t nframes = list->GetSize();
00087    TClass *cl;
00088    for (Int_t i=0; i<nframes; i++) {
00089       el = (TGFrameElement *)list->At(i);
00090       cl = el->fFrame->IsA();
00091       if (cl==TGCompositeFrame::Class() || cl==TGHorizontalFrame::Class() || cl==TGVerticalFrame::Class())
00092          Cleanup((TGCompositeFrame*)el->fFrame);
00093    }
00094    frame->Cleanup();
00095 }   
00096 
00097 //______________________________________________________________________________
00098 void TGeoTabManager::GetShapeEditor(TGeoShape *shape)
00099 {
00100 // Get editor for a shape.
00101    if (!shape) return;
00102    if (!fShapePanel) fShapePanel = new TGeoTransientPanel(fGedEditor, "Shape", shape);
00103    else {
00104       fShapePanel->SetModel(shape);   
00105       fShapePanel->Show();
00106    }   
00107 }
00108 
00109 //______________________________________________________________________________
00110 void TGeoTabManager::GetVolumeEditor(TGeoVolume *volume)
00111 {
00112 // Get editor for a volume.
00113    if (!volume || !fVolumeTab) return;
00114    GetEditors(TAttLine::Class());
00115    GetEditors(TGeoVolume::Class());
00116    fVolumeTab->MapSubwindows();
00117    fVolumeTab->Layout();
00118    SetModel(volume);
00119 }
00120    
00121 //______________________________________________________________________________
00122 void TGeoTabManager::GetMatrixEditor(TGeoMatrix *matrix)
00123 {
00124 // Get editor for a matrix.
00125    if (!matrix) return;
00126    if (!fMatrixPanel) fMatrixPanel = new TGeoTransientPanel(fGedEditor, "Matrix", matrix);
00127    else {
00128       fMatrixPanel->SetModel(matrix);
00129       fMatrixPanel->Show();
00130    }   
00131 }
00132 
00133 //______________________________________________________________________________
00134 void TGeoTabManager::GetMediumEditor(TGeoMedium *medium)
00135 {
00136 // Get editor for a medium.
00137    if (!medium) return;
00138    if (!fMediumPanel) fMediumPanel = new TGeoTransientPanel(fGedEditor, "Medium", medium);
00139    else {
00140       fMediumPanel->SetModel(medium);
00141       fMediumPanel->Show();
00142       fMediumPanel->RaiseWindow();
00143    }   
00144 }
00145 
00146 //______________________________________________________________________________
00147 void TGeoTabManager::GetMaterialEditor(TGeoMaterial *material)
00148 {
00149 // Get editor for a material.
00150    if (!material) return;
00151    TString name = "Material";
00152    if (material->IsMixture()) name = "Mixture";
00153    if (!fMaterialPanel) fMaterialPanel = new TGeoTransientPanel(fGedEditor, name.Data(), material);
00154    else {
00155       fMaterialPanel->SetModel(material);
00156       fMaterialPanel->Show();
00157       fMaterialPanel->RaiseWindow();
00158    }   
00159 }
00160 
00161 //______________________________________________________________________________
00162 void TGeoTabManager::GetEditors(TClass *cl)
00163 {
00164 // Get editor for a class.
00165    // Look in fVolumeTab for any object deriving from TGedFrame,
00166 
00167    TClass *class2 = TClass::GetClass(TString::Format("%sEditor",cl->GetName()));
00168    if (class2 && class2->InheritsFrom(TGedFrame::Class())) {
00169       TGFrameElement *fr;
00170       TIter next(fVolumeTab->GetList());
00171       while ((fr = (TGFrameElement *) next())) if (fr->fFrame->IsA() == class2) return;
00172       TGClient *client = fGedEditor->GetClient();
00173       TGWindow *exroot = (TGWindow*) client->GetRoot();
00174       client->SetRoot(fVolumeTab);
00175       TGedEditor::SetFrameCreator(fGedEditor);
00176       TGedFrame* gfr = reinterpret_cast<TGedFrame*>(class2->New());
00177       gfr->SetModelClass(cl);
00178       TGedEditor::SetFrameCreator(0);
00179       client->SetRoot(exroot);
00180       fVolumeTab->AddFrame(gfr, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
00181       gfr->MapSubwindows();
00182    }
00183 }
00184 
00185 //______________________________________________________________________________
00186 TGeoTabManager *TGeoTabManager::GetMakeTabManager(TGedEditor *ged)
00187 {
00188 // Static method to return the tab manager currently appended to the pad or create one 
00189 // if not existing.
00190    if (!ged) return NULL;
00191    TPair *pair = (TPair*) fgEditorToMgrMap.FindObject(ged);
00192    if (pair) {
00193       return (TGeoTabManager*) pair->Value();
00194    } else {
00195       TGeoTabManager *tabmgr = new TGeoTabManager(ged); // added to fgEditorToMgrMap in ctor
00196       return tabmgr;
00197    }
00198 }   
00199 
00200 //______________________________________________________________________________
00201 Int_t TGeoTabManager::GetTabIndex() const
00202 {
00203 // Get index for a given tab element.
00204    Int_t ntabs = fTab->GetNumberOfTabs();
00205    TString tabname = "Volume";
00206                      
00207    TGTabElement *tel;
00208    for (Int_t i=0; i<ntabs; i++) {
00209       tel = fTab->GetTabTab(i);
00210       if (tel && !strcmp(tel->GetString(),tabname.Data())) return i;
00211    }   
00212    return 0;
00213 }
00214 
00215 //______________________________________________________________________________
00216 void TGeoTabManager::MoveFrame(TGCompositeFrame *fr, TGCompositeFrame *p)
00217 {
00218 // Move frame fr at the end of the list of parent p.
00219    TList *list = p->GetList();
00220    TIter next(list);
00221    TGFrameElement *el = 0;
00222    while ((el=(TGFrameElement*)next())) {
00223       if (el->fFrame == fr) break;
00224    }  
00225    if (el) { 
00226       list->Remove(el);
00227       list->Add(el);
00228    }   
00229 }
00230 
00231 //______________________________________________________________________________
00232 void TGeoTabManager::SetVolTabEnabled(Bool_t flag)
00233 {
00234 // Enable/disable tabs
00235    fTab->SetEnabled(GetTabIndex(), flag);
00236 }
00237 
00238 //______________________________________________________________________________
00239 void TGeoTabManager::SetModel(TObject *model)
00240 {
00241 // Send the SetModel signal to all editors in the tab TYPE.
00242    TGCompositeFrame *tab = fVolumeTab;
00243    fVolume = (TGeoVolume*)model;
00244    TGFrameElement *el;
00245    TIter next(tab->GetList());
00246    while ((el = (TGFrameElement *) next())) {
00247       if ((el->fFrame)->InheritsFrom(TGedFrame::Class())) {
00248          ((TGedFrame *)(el->fFrame))->SetModel(model);
00249       }   
00250    }
00251 }      
00252 
00253 //______________________________________________________________________________
00254 void TGeoTabManager::SetTab()
00255 {
00256 // Set a given tab element as active one.
00257    fTab->SetTab(GetTabIndex());
00258 }
00259    
00260 ClassImp(TGeoTreeDialog)
00261 
00262 TObject *TGeoTreeDialog::fgSelectedObj = 0;
00263 
00264 //______________________________________________________________________________
00265 TObject *TGeoTreeDialog::GetSelected() 
00266 {
00267    //static; return selected object
00268    return fgSelectedObj;
00269 }
00270 
00271 //______________________________________________________________________________
00272 TGeoTreeDialog::TGeoTreeDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
00273                :TGTransientFrame(main, main, w, h)
00274 {
00275 // Constructor
00276    fgSelectedObj = 0;
00277    fCanvas = new TGCanvas(this, 100, 200,  kSunkenFrame | kDoubleBorder);
00278    fLT = new TGListTree(fCanvas->GetViewPort(), 100, 200);
00279    fLT->Associate(this);
00280    fCanvas->SetContainer(fLT);
00281    AddFrame(fCanvas, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2,2,2,2));
00282    f1 = new TGCompositeFrame(this, 100, 10, kHorizontalFrame | kLHintsExpandX);
00283    fObjLabel = new TGLabel(f1, "Selected: -none-");
00284    Pixel_t color;
00285    gClient->GetColorByName("#0000ff", color);
00286    fObjLabel->SetTextColor(color);
00287    fObjLabel->ChangeOptions(kSunkenFrame | kDoubleBorder);
00288    f1->AddFrame(fObjLabel, new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 2,2,2,2));
00289    fClose = new TGTextButton(f1, "&Close");
00290    fClose->Associate(this);
00291    f1->AddFrame(fClose, new TGLayoutHints(kLHintsRight, 2,2,2,2)); 
00292    AddFrame(f1, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 2,2,2,2));
00293    
00294    Int_t ww = caller->GetWidth();
00295    Window_t wdum;
00296    Int_t    ax, ay;
00297    gVirtualX->TranslateCoordinates(caller->GetId(), main->GetId(), 0,0,ax,ay,wdum);
00298    Move(ax + ww, ay);
00299    SetWMPosition(ax, ay);
00300    
00301 }
00302 
00303 //______________________________________________________________________________
00304 TGeoTreeDialog::~TGeoTreeDialog()
00305 {
00306 // Destructor
00307    delete fClose;
00308    delete fObjLabel;
00309    delete f1;
00310    delete fLT;
00311    delete fCanvas;
00312 }
00313 
00314 //______________________________________________________________________________
00315 void TGeoTreeDialog::DoSelect(TGListTreeItem *item)
00316 {
00317 // Update dialog to reflect current clicked object.
00318    static TString name;
00319    if (!item || !item->GetUserData()) {
00320       fgSelectedObj = 0;
00321       name = "Selected: -none-";
00322       fObjLabel->SetText(name);
00323       return;
00324    }
00325    fgSelectedObj = (TObject *)item->GetUserData();
00326    if (fgSelectedObj) {
00327       name = TString::Format("Selected %s", fgSelectedObj->GetName());
00328       fObjLabel->SetText(name);
00329    }   
00330 }   
00331       
00332 ClassImp(TGeoVolumeDialog)
00333 
00334 //______________________________________________________________________________
00335 TGeoVolumeDialog::TGeoVolumeDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
00336                  :TGeoTreeDialog(caller, main, w, h)
00337 {
00338 // Ctor.
00339    BuildListTree();   
00340    ConnectSignalsToSlots();
00341    MapSubwindows();
00342    Layout();
00343    SetWindowName("Volume dialog");
00344    MapWindow();
00345    gClient->WaitForUnmap(this);
00346 }
00347 
00348 //______________________________________________________________________________
00349 void TGeoVolumeDialog::BuildListTree()
00350 {
00351 // Build volume specific list tree.
00352    const TGPicture *pic_fld = gClient->GetPicture("folder_t.xpm");
00353    const TGPicture *pic_fldo = gClient->GetPicture("ofolder_t.xpm");
00354    const TGPicture *pic_file = gClient->GetPicture("mdi_default.xpm");
00355    const TGPicture *pic_fileo = gClient->GetPicture("fileopen.xpm");
00356    TGListTreeItem *parent_item=0;
00357    TGeoVolume *parent_vol = gGeoManager->GetMasterVolume();
00358    TGeoVolume *vol;
00359    // Existing volume hierarchy
00360    parent_item = fLT->AddItem(parent_item, "Volume hierarchy", pic_fldo, pic_fld);
00361    parent_item->SetTipText("Select a volume from the existing hierarchy");
00362    fLT->OpenItem(parent_item);
00363    if (parent_vol) {
00364       if (!parent_vol->GetNdaughters()) {
00365          parent_item = fLT->AddItem(parent_item, parent_vol->GetName(), parent_vol, pic_fileo, pic_file);
00366          parent_item->SetTipText("Master volume");
00367          fLT->SetSelected(parent_item);
00368       } else {
00369          parent_item = fLT->AddItem(parent_item, parent_vol->GetName(), parent_vol, pic_fldo, pic_fld);
00370          parent_item->SetTipText("Master volume");
00371          fLT->SetSelected(parent_item);
00372       }
00373    }
00374    parent_item = fLT->AddItem(NULL, "Other volumes", pic_fldo, pic_fld);
00375    parent_item->SetTipText("Select a volume from the list of unconnected volumes");
00376    TIter next1(gGeoManager->GetListOfVolumes());
00377    Bool_t found = kFALSE;
00378    while ((vol=(TGeoVolume*)next1())) {
00379       if (vol->IsAdded()) continue;
00380       fLT->AddItem(parent_item, vol->GetName(), vol, pic_fileo, pic_file);
00381       found = kTRUE;
00382    }
00383    if (found) {    
00384 //      fLT->OpenItem(parent_item);   
00385       if (!parent_vol) fLT->SetSelected(parent_item->GetFirstChild());
00386    }        
00387 }
00388 
00389 //______________________________________________________________________________
00390 void TGeoVolumeDialog::DoClose()
00391 {
00392 // Handle close button.
00393    DeleteWindow();
00394 }   
00395 
00396 //______________________________________________________________________________
00397 void TGeoVolumeDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
00398 {
00399 // Handle item click.
00400    // Iterate daughters
00401    if (btn!=kButton1) return;
00402    DoSelect(item);   
00403    if (!item || !item->GetUserData()) return;
00404    const TGPicture *pic_fld = gClient->GetPicture("folder_t.xpm");
00405    const TGPicture *pic_fldo = gClient->GetPicture("ofolder_t.xpm");
00406    const TGPicture *pic_file = gClient->GetPicture("mdi_default.xpm");
00407    const TGPicture *pic_fileo = gClient->GetPicture("fileopen.xpm");
00408    TGeoVolume *parent_vol = (TGeoVolume*)item->GetUserData();
00409    TGeoVolume *vol;
00410    TGeoNode *crtnode;
00411    TGListTreeItem *daughter_item;
00412    Int_t i,j,ind,icopy;
00413    Int_t nd = parent_vol->GetNdaughters();
00414    for (i=0; i<nd; i++) {
00415       icopy = 0;
00416       crtnode = parent_vol->GetNode(i);
00417       vol = crtnode->GetVolume();
00418       // check if the volume is replicated in the parent
00419       ind = parent_vol->GetIndex(crtnode);
00420       for (j=0; j<ind; j++) if (parent_vol->GetNode(j)->GetVolume() == vol) break;
00421       if (i<ind) continue;
00422       icopy++;
00423       for (j=ind+1; j<nd; j++) if (parent_vol->GetNode(j)->GetVolume() == vol) icopy++;
00424       daughter_item = fLT->AddItem(item, ((icopy>1)?(TString::Format("%s (%i)",vol->GetName(),icopy)).Data():vol->GetName()), 
00425                     vol,((vol->GetNdaughters())?pic_fldo:pic_fileo), ((vol->GetNdaughters())?pic_fld:pic_file));
00426       if (strlen(vol->GetTitle())) daughter_item->SetTipText(vol->GetTitle());            
00427    }
00428    if (nd) gClient->NeedRedraw(fLT);
00429 }   
00430 
00431 //______________________________________________________________________________
00432 void TGeoVolumeDialog::ConnectSignalsToSlots()
00433 {
00434 // Connect signals to slots.
00435    fClose->Connect("Clicked()", "TGeoVolumeDialog", this, "DoClose()");
00436    fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoVolumeDialog", this, 
00437                 "DoItemClick(TGListTreeItem *, Int_t)");
00438 }
00439 
00440 ClassImp(TGeoShapeDialog)
00441 
00442 //______________________________________________________________________________
00443 TGeoShapeDialog::TGeoShapeDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
00444                  :TGeoTreeDialog(caller, main, w, h)
00445 {
00446 // Ctor.
00447    BuildListTree();   
00448    ConnectSignalsToSlots();
00449    MapSubwindows();
00450    Layout();
00451    SetWindowName("Shape dialog");
00452    MapWindow();
00453    gClient->WaitForUnmap(this);
00454 }
00455 
00456 //______________________________________________________________________________
00457 void TGeoShapeDialog::BuildListTree()
00458 {
00459 // Build shape specific list tree.
00460    const TGPicture *pic_fld = gClient->GetPicture("folder_t.xpm");
00461    const TGPicture *pic_fldo = gClient->GetPicture("ofolder_t.xpm");
00462    const TGPicture *pic_shape;
00463    TGListTreeItem *parent_item=0;
00464    TGeoShape *shape;
00465    const char *shapename;
00466    TString fld_name;
00467    Int_t nshapes = gGeoManager->GetListOfShapes()->GetEntriesFast();
00468    if (!nshapes) return;
00469    // Existing shapes
00470    for (Int_t i=0; i<nshapes; i++) {
00471       shape = (TGeoShape*)gGeoManager->GetListOfShapes()->At(i);
00472       shapename = shape->IsA()->GetName();
00473       pic_shape = fClient->GetMimeTypeList()->GetIcon(shapename, kTRUE);
00474       fld_name = shapename;  // e.g. "TGeoBBox"
00475       fld_name.Remove(0,4); // remove "TGeo" part -> "BBox"
00476       fld_name += " Shapes";
00477       parent_item = fLT->FindChildByName(NULL, fld_name.Data());
00478       if (!parent_item) {
00479          parent_item = fLT->AddItem(NULL, fld_name.Data(), pic_fldo, pic_fld);
00480          parent_item->SetTipText(TString::Format("List of %s shapes",fld_name.Data()));
00481       }
00482       fLT->AddItem(parent_item, shape->GetName(), shape, pic_shape, pic_shape);
00483    }   
00484 }
00485 
00486 //______________________________________________________________________________
00487 void TGeoShapeDialog::DoClose()
00488 {
00489 // Handle close button.
00490    DeleteWindow();
00491 }   
00492 
00493 //______________________________________________________________________________
00494 void TGeoShapeDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
00495 {
00496 // Handle item click.
00497    // Iterate daughters
00498    if (btn!=kButton1) return;
00499    DoSelect(item);   
00500    if (!item || !item->GetUserData()) return;
00501 }   
00502 
00503 //______________________________________________________________________________
00504 void TGeoShapeDialog::ConnectSignalsToSlots()
00505 {
00506 // Connect signals to slots.
00507    fClose->Connect("Clicked()", "TGeoShapeDialog", this, "DoClose()");
00508    fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoShapeDialog", this, 
00509                 "DoItemClick(TGListTreeItem *, Int_t)");
00510 }
00511 
00512 ClassImp(TGeoMediumDialog)
00513 
00514 //______________________________________________________________________________
00515 TGeoMediumDialog::TGeoMediumDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
00516                  :TGeoTreeDialog(caller, main, w, h)
00517 {
00518 // Ctor.
00519    BuildListTree();   
00520    ConnectSignalsToSlots();
00521    MapSubwindows();
00522    Layout();
00523    SetWindowName("Medium dialog");
00524    MapWindow();
00525    gClient->WaitForUnmap(this);
00526 }
00527 
00528 //______________________________________________________________________________
00529 void TGeoMediumDialog::BuildListTree()
00530 {
00531 // Build volume specific list tree.
00532    const TGPicture *pic_med = gClient->GetPicture("geomedium_t.xpm");;
00533    TGeoMedium *med;
00534    Int_t nmed = gGeoManager->GetListOfMedia()->GetSize();
00535    if (!nmed) return;
00536    // Existing media
00537    for (Int_t i=0; i<nmed; i++) {
00538       med = (TGeoMedium*)gGeoManager->GetListOfMedia()->At(i);
00539       fLT->AddItem(NULL, med->GetName(), med, pic_med, pic_med);
00540    }   
00541 }
00542 
00543 //______________________________________________________________________________
00544 void TGeoMediumDialog::DoClose()
00545 {
00546 // Handle close button.
00547    DeleteWindow();
00548 }   
00549 
00550 //______________________________________________________________________________
00551 void TGeoMediumDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
00552 {
00553 // Handle item click.
00554    // Iterate daughters
00555    if (btn!=kButton1) return;
00556    DoSelect(item);   
00557    if (!item || !item->GetUserData()) return;
00558    //gClient->NeedRedraw(fLT);
00559 }   
00560 
00561 //______________________________________________________________________________
00562 void TGeoMediumDialog::ConnectSignalsToSlots()
00563 {
00564 // Connect signals to slots.
00565    fClose->Connect("Clicked()", "TGeoMediumDialog", this, "DoClose()");
00566    fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoMediumDialog", this, 
00567                 "DoItemClick(TGListTreeItem *, Int_t)");
00568 }
00569 
00570 ClassImp(TGeoMaterialDialog)
00571 
00572 //______________________________________________________________________________
00573 TGeoMaterialDialog::TGeoMaterialDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
00574                  :TGeoTreeDialog(caller, main, w, h)
00575 {
00576 // Ctor.
00577    BuildListTree();   
00578    ConnectSignalsToSlots();
00579    MapSubwindows();
00580    Layout();
00581    SetWindowName("Material dialog");
00582    MapWindow();
00583    gClient->WaitForUnmap(this);
00584 }
00585 
00586 //______________________________________________________________________________
00587 void TGeoMaterialDialog::BuildListTree()
00588 {
00589 // Build volume specific list tree.
00590    const TGPicture *pic_mat = gClient->GetPicture("geomaterial_t.xpm");;
00591    TGeoMaterial *mat;
00592    Int_t nmat = gGeoManager->GetListOfMaterials()->GetSize();
00593    if (!nmat) return;
00594    // Existing materials
00595    for (Int_t i=0; i<nmat; i++) {
00596       mat = (TGeoMaterial*)gGeoManager->GetListOfMaterials()->At(i);
00597       fLT->AddItem(NULL, mat->GetName(), mat, pic_mat, pic_mat);
00598    }   
00599 }
00600 
00601 //______________________________________________________________________________
00602 void TGeoMaterialDialog::DoClose()
00603 {
00604 // Handle close button.
00605    DeleteWindow();
00606 }   
00607 
00608 //______________________________________________________________________________
00609 void TGeoMaterialDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
00610 {
00611 // Handle item click.
00612    // Iterate daughters
00613    if (btn!=kButton1) return;
00614    DoSelect(item);   
00615    if (!item || !item->GetUserData()) return;
00616    //gClient->NeedRedraw(fLT);
00617 }   
00618 
00619 //______________________________________________________________________________
00620 void TGeoMaterialDialog::ConnectSignalsToSlots()
00621 {
00622 // Connect signals to slots.
00623    fClose->Connect("Clicked()", "TGeoMaterialDialog", this, "DoClose()");
00624    fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoMaterialDialog", this, 
00625                 "DoItemClick(TGListTreeItem *, Int_t)");
00626 }
00627 
00628 ClassImp(TGeoMatrixDialog)
00629 
00630 //______________________________________________________________________________
00631 TGeoMatrixDialog::TGeoMatrixDialog(TGFrame *caller, const TGWindow *main, UInt_t w, UInt_t h)
00632                  :TGeoTreeDialog(caller, main, w, h)
00633 {
00634 // Ctor.
00635    BuildListTree();   
00636    ConnectSignalsToSlots();
00637    MapSubwindows();
00638    Layout();
00639    SetWindowName("Matrix dialog");
00640    MapWindow();
00641    gClient->WaitForUnmap(this);
00642 }
00643 
00644 //______________________________________________________________________________
00645 void TGeoMatrixDialog::BuildListTree()
00646 {
00647 // Build matrix specific list tree.
00648    const TGPicture *pic_tr = gClient->GetPicture("geotranslation_t.xpm");
00649    const TGPicture *pic_rot = gClient->GetPicture("georotation_t.xpm");
00650    const TGPicture *pic_combi = gClient->GetPicture("geocombi_t.xpm");
00651    const TGPicture *pic;
00652    TGListTreeItem *parent_item=0;
00653    TGeoMatrix *matrix;
00654    Int_t nmat = gGeoManager->GetListOfMatrices()->GetEntriesFast();
00655    if (!nmat) return;
00656    // Existing matrices
00657    for (Int_t i=0; i<nmat; i++) {
00658       matrix = (TGeoMatrix*)gGeoManager->GetListOfMatrices()->At(i);
00659       if (matrix->IsIdentity()) continue;
00660       if (!strcmp(matrix->IsA()->GetName(),"TGeoTranslation")) {
00661          pic = pic_tr;
00662          parent_item = fLT->FindChildByName(NULL, "Translations");
00663          if (!parent_item) {
00664             parent_item = fLT->AddItem(NULL, "Translations", pic, pic);
00665             parent_item->SetTipText("List of translations");
00666          }            
00667       } else if (!strcmp(matrix->IsA()->GetName(),"TGeoRotation")) {
00668          pic = pic_rot;
00669          parent_item = fLT->FindChildByName(NULL, "Rotations");
00670          if (!parent_item) {
00671             parent_item = fLT->AddItem(NULL, "Rotations", pic, pic);
00672             parent_item->SetTipText("List of rotations");
00673          } 
00674       } else if (!strcmp(matrix->IsA()->GetName(),"TGeoCombiTrans") ||
00675                   !strcmp(matrix->IsA()->GetName(),"TGeoHMatrix")) {
00676          pic = pic_combi;
00677          parent_item = fLT->FindChildByName(NULL, "Combined");
00678          if (!parent_item) {
00679             parent_item = fLT->AddItem(NULL, "Combined", pic, pic);
00680             parent_item->SetTipText("List of combined transformations");
00681          } 
00682       } else continue;
00683       fLT->AddItem(parent_item, matrix->GetName(), matrix, pic, pic);
00684    }   
00685 }
00686 
00687 //______________________________________________________________________________
00688 void TGeoMatrixDialog::DoClose()
00689 {
00690 // Handle close button.
00691    DeleteWindow();
00692 }   
00693 
00694 //______________________________________________________________________________
00695 void TGeoMatrixDialog::DoItemClick(TGListTreeItem *item, Int_t btn)
00696 {
00697 // Handle item click.
00698    // Iterate daughters
00699    if (btn!=kButton1) return;
00700    DoSelect(item);   
00701    if (!item || !item->GetUserData()) return;
00702    //gClient->NeedRedraw(fLT);
00703 }   
00704 
00705 //______________________________________________________________________________
00706 void TGeoMatrixDialog::ConnectSignalsToSlots()
00707 {
00708 // Connect signals to slots.
00709    fClose->Connect("Clicked()", "TGeoMatrixDialog", this, "DoClose()");
00710    fLT->Connect("Clicked(TGListTreeItem *, Int_t)", "TGeoMatrixDialog", this, 
00711                 "DoItemClick(TGListTreeItem *, Int_t)");
00712 }
00713 
00714 ClassImp(TGeoTransientPanel)
00715 
00716 //______________________________________________________________________________
00717 TGeoTransientPanel::TGeoTransientPanel(TGedEditor* ged, const char *name, TObject *obj)
00718                    :TGMainFrame(gClient->GetRoot(),175,20)
00719 {
00720 // Transient panel ctor.
00721    fGedEditor = ged;
00722    fModel = obj;
00723    fCan = new TGCanvas(this, 170, 100);
00724    fTab = new TGTab(fCan->GetViewPort(), 10, 10);
00725    fCan->SetContainer(fTab);
00726    AddFrame(fCan, new TGLayoutHints(kLHintsExpandY | kLHintsExpandX));
00727    fTab->Associate(fCan);
00728    fTabContainer = fTab->AddTab(name);
00729    fStyle = new TGCompositeFrame(fTabContainer, 110, 30, kVerticalFrame);
00730    fTabContainer->AddFrame(fStyle, new TGLayoutHints(kLHintsTop | kLHintsExpandX,\
00731                                                      5, 0, 2, 2));
00732    TString wname = name;
00733    wname += " Editor";
00734    SetWindowName(wname.Data());
00735    SetModel(fModel);
00736    fClose = new TGTextButton(this, "Close");
00737    AddFrame(fClose, new TGLayoutHints(kLHintsBottom | kLHintsRight, 0,10,5,5));
00738    MapSubwindows();
00739    Layout();
00740    Resize(fTabContainer->GetDefaultWidth()+30, fTabContainer->GetDefaultHeight()+65);
00741    MapWindow();
00742    gROOT->GetListOfCleanups()->Add(this);
00743    fClose->Connect("Clicked()", "TGeoTransientPanel", this, "Hide()");
00744 } 
00745 
00746 //______________________________________________________________________________
00747 TGeoTransientPanel::~TGeoTransientPanel()
00748 {
00749 // Destructor.
00750    DeleteEditors();
00751    delete fTab;
00752    delete fCan;
00753    gROOT->GetListOfCleanups()->Remove(this);
00754 }
00755 
00756 //______________________________________________________________________________
00757 void TGeoTransientPanel::CloseWindow()
00758 {
00759    // When closed via WM close button, just unmap (i.e. hide) editor
00760    // for later use.
00761    UnmapWindow();
00762    gROOT->GetListOfCleanups()->Remove(this);
00763 }
00764 
00765 //______________________________________________________________________________
00766 void TGeoTransientPanel::GetEditors(TClass *cl)
00767 {
00768 // Get editor for a class.
00769    // Look in fStyle for any object deriving from TGedFrame,
00770 
00771    TClass *class2 = TClass::GetClass(TString::Format("%sEditor",cl->GetName()));
00772    if (class2 && class2->InheritsFrom(TGedFrame::Class())) {
00773       TGFrameElement *fr;
00774       TIter next(fStyle->GetList());
00775       while ((fr = (TGFrameElement *) next()))
00776          if (fr->fFrame->IsA() == class2) return;
00777       TGClient *client = fGedEditor->GetClient();
00778       TGWindow *exroot = (TGWindow*) client->GetRoot();
00779       client->SetRoot(fStyle);
00780       TGedEditor::SetFrameCreator(fGedEditor);
00781       TGedFrame* gfr = reinterpret_cast<TGedFrame*>(class2->New());
00782       gfr->SetModelClass(cl);
00783       TGedEditor::SetFrameCreator(0);
00784       client->SetRoot(exroot);
00785       fStyle->AddFrame(gfr, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
00786       gfr->MapSubwindows();
00787    }
00788 }
00789 
00790 //______________________________________________________________________________
00791 void TGeoTransientPanel::SetModel(TObject *model)
00792 {
00793 // Update the editors in the main tab to reflect the selected object.
00794    if (!model) return;
00795    fModel = model;
00796    GetEditors(model->IsA());
00797    TGFrameElement *el;
00798    TIter next(fStyle->GetList());
00799    while ((el = (TGFrameElement *) next())) {
00800       if ((el->fFrame)->InheritsFrom(TGedFrame::Class())) {
00801          ((TGedFrame *)(el->fFrame))->SetModel(model);
00802       }   
00803    }
00804    Resize(fTabContainer->GetDefaultWidth()+30, fTabContainer->GetDefaultHeight()+65);
00805 }
00806 
00807 //______________________________________________________________________________
00808 void TGeoTransientPanel::Hide()
00809 {
00810 // Hide the transient frame
00811    UnmapWindow();
00812 }
00813 
00814 //______________________________________________________________________________
00815 void TGeoTransientPanel::Show()
00816 {
00817 // Hide the transient frame
00818    MapWindow();
00819 }
00820 
00821 //______________________________________________________________________________
00822 void TGeoTransientPanel::DeleteEditors()
00823 {
00824 // Delete editors.
00825    fStyle->Cleanup();
00826 }
00827 
00828    

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