]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4GeometryGUI.cxx
673e2c4dcd6373b5e2e323e1ebdb035979e818a1
[u/mrichter/AliRoot.git] / TGeant4 / TG4GeometryGUI.cxx
1 // $Id$
2 // Category: interfaces
3 //
4 // Author: D. Adamova
5 //==============================================================
6 //
7 //----------------TG4GeometryGUI.cxx--------------------------//
8 //----------------AG4 Geometry Browser----------------------//
9 //
10 //=================================================================
11
12   
13                  
14 #include "TG4GeometryGUI.h"
15 #include "TG4GuiVolume.h"
16 #include "TG4MainFrame.h"
17 #include "TG4ListTreeFrame.h"
18 #include "TG4VolumesFrames.h"
19 #include "TG4MaterialsFrames.h"
20 #include "TG4Globals.h"
21
22 #include <G4LogicalVolume.hh>
23 #include <G4VPhysicalVolume.hh>
24 #include <G4LogicalVolumeStore.hh>
25 #include <TGListTree.h>
26 #include <TObjArray.h>
27
28
29                  
30 ClassImp(TG4GeometryGUI)    
31
32 TG4GeometryGUI::TG4GeometryGUI()
33 {
34 //---> Constructor               
35     fPanel   =   new TG4MainFrame(gClient->GetRoot(), 650, 500);
36
37     G4cout << "\n***********************************************" << G4endl;
38     G4cout << "***********************************************" << G4endl;
39     G4cout << " Welcome to the Geometry Browser for AliGeant4 " << G4endl;
40     G4cout << "\n***********************************************" << G4endl;
41     G4cout << "***********************************************\n" << G4endl;
42     
43     ReadGeometryTree();
44     
45     ReadMaterials();  
46
47  }
48  
49 TG4GeometryGUI::TG4GeometryGUI(const TG4GeometryGUI& gg) 
50 {
51 // Dummy copy constructor 
52   TG4Globals::Exception(
53     "Attempt to use TG4GeometryGUI copy constructor.");
54 }
55
56 TG4GeometryGUI& TG4GeometryGUI::operator=(const TG4GeometryGUI& gg)
57 {
58   // check assignement to self
59   if (this == &gg) return *this;
60
61   TG4Globals::Exception(
62     "Attempt to assign TG4GeometryGUI singleton.");
63     
64   return *this;  
65 }    
66
67 TG4GeometryGUI::~TG4GeometryGUI(){
68 //---> liquidator
69
70   G4cout << "\n Now in TG4GeometryGUI destructor \n" << G4endl;
71   delete fPanel;
72 // ----> guiVolumes not taken care of yet
73
74 }
75
76 void TG4GeometryGUI::ReadGeometryTree()
77 {
78 //--->Linking logical volumes to gui volumes
79
80 //  Icons for folders
81     const TGPicture* kFolder     = gClient->GetPicture("folder_t.xpm");
82     const TGPicture* kOpenFolder = gClient->GetPicture("ofolder_t.xpm");
83     const TGPicture* kDocument   = gClient->GetPicture("doc_t.xpm");
84     TG4GuiVolume*  volume;
85
86     G4LogicalVolumeStore* volumeStore;
87     G4LogicalVolume* top;
88          
89     TGListTreeItem* itemi;
90     
91     volumeStore = G4LogicalVolumeStore::GetInstance();
92     top = (*volumeStore )[0];  
93
94     G4String vname = top->GetName();
95     volume = new TG4GuiVolume( vname, top);//--->TObject
96     itemi = fPanel->GetListTreeFrame()
97       ->AddItem(volume,0,vname, kOpenFolder, kFolder);
98  
99     RegisterLogicalVolume( top, itemi);
100     
101 //    delete volume; ---> inactivated to get UserData  for the
102 //                   ---> ListTree items in the MainFrame
103  
104 }          
105
106 void TG4GeometryGUI::RegisterLogicalVolume(G4LogicalVolume* lv,
107                                            TGListTreeItem* itemv) 
108 {
109 //--->Filling  up gui volumes objArray  
110
111 typedef G4std::set <G4String, G4std::less<G4String> > TG4StringSet;
112 TG4StringSet     lVolumeNames;     //set of names of solids  
113
114 //  Icons for folders
115     const TGPicture* kFolder     = gClient->GetPicture("folder_t.xpm");
116     const TGPicture* kOpenFolder = gClient->GetPicture("ofolder_t.xpm");
117  
118   TG4GuiVolume*  volume;
119   G4LogicalVolume* lDaughter;
120   G4VPhysicalVolume* pDaughter;
121   TGListTreeItem* itemi;
122  
123   G4int nofDaughters = lv->GetNoDaughters();
124   if (nofDaughters == 0) return;
125
126 //---------->only for nofDaughters > 0  
127   // open composition
128   G4String lvName = lv->GetName();
129   TObjArray* guiVolumes = new TObjArray();
130   
131  
132   G4int ii;
133   for (ii=0; ii<nofDaughters; ii++) {
134  
135     pDaughter = lv->GetDaughter(ii);
136     lDaughter = pDaughter->GetLogicalVolume();
137     G4String vname = lDaughter->GetName();
138
139 //-------> process lv only if it was not yet processed
140     if ( (lVolumeNames.find(vname)) == (lVolumeNames.end()) ) {
141
142       volume = new TG4GuiVolume( vname, lDaughter);
143       itemi = fPanel->GetListTreeFrame()
144         ->AddItem(volume, itemv, vname, kOpenFolder, kFolder);
145       
146       itemi->SetUserData(volume);
147       
148       volume->SetItem( itemi);
149
150 //-----> store the name of logical volume in the set
151       lVolumeNames.insert(lVolumeNames.begin(),vname); 
152       guiVolumes->AddLast( volume );
153    };
154  
155  }; 
156   
157
158 //-----> process daughters
159     for (ii=0; ii<guiVolumes->GetEntriesFast(); ii++) {
160
161       TG4GuiVolume* guiVolume = (TG4GuiVolume*)(guiVolumes->At(ii));
162       G4LogicalVolume* lvd = guiVolume->GetLogicalVolume();
163       TGListTreeItem* itemvd = guiVolume->GetItem();
164       RegisterLogicalVolume(lvd, itemvd);
165   };
166   
167   delete guiVolumes;
168 //  delete volume;---> if deleted, wrong logical volumes assigned 
169 //                ---> to the ListTree items in the MainFrame display
170 }  
171
172 void TG4GeometryGUI::ReadMaterials() const
173 {
174 //-----> Puts logical volumes and materials names 
175 //-----> into ComboBoxes 
176     TG4VolumesFrames* vFrame = fPanel->GetVolumesFrames();
177     vFrame->SetVolumesComboEntries();
178
179     TG4MaterialsFrames* mFrame = fPanel->GetMaterialsFrames();
180     mFrame->SetMaterialsComboEntries();
181
182 }
183