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