]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4MaterialsFrames.cxx
upgrade: all volumes list tree related functions/data moved from TG4MainFrame to...
[u/mrichter/AliRoot.git] / TGeant4 / TG4MaterialsFrames.cxx
1 // $Id$
2 // Category: interfaces
3 //
4 // Author: D. Adamova
5 //
6 //========================================================
7 //
8 //------------TG4MaterialsFrames.cxx--------------------------------//
9 //--------- Frames for the the display of materials properties---//
10 //
11 //========================================================= 
12  
13 #include "TG4MaterialsFrames.h" 
14 #include "TG4Globals.h"
15
16 #include <TGTextBuffer.h>
17 #include <TGTextEntry.h>
18 #include <TGComboBox.h>
19 #include <TGLabel.h>
20  
21 #include <G4Material.hh>
22 #include <G4Element.hh>
23
24
25
26  ClassImp(TG4MaterialsFrames)
27
28 TG4MaterialsFrames::TG4MaterialsFrames( TGCompositeFrame* Parent, TGMainFrame* ActionFrame )
29
30 //---> creates the materials properties display frame
31 //---> and plunges it into the main frame
32    fCapFrame = new TGCompositeFrame(Parent, 60, 20, kHorizontalFrame);
33    ULong_t back= TGFrame::GetBlackPixel(); 
34    fCapFrame->ChangeBackground(back);   
35    fMatSubframe1 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
36    fMatFrameLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
37
38    // ComboBox for materials
39    fMaterialsCombo = new TGComboBox(fMatSubframe1, 200);
40    TGLayoutHints* lLayoutHints3 = 
41              new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
42                            2, 2, 2, 2);   
43    Text_t* lComboLabelText = " Pick up a material here ";
44    fComboLabel = new TGLabel( fMatSubframe1, lComboLabelText);
45    fMatSubframe1->AddFrame(fComboLabel, lLayoutHints3);
46    fMatSubframe1->AddFrame(fMaterialsCombo, fMatFrameLayout);
47
48
49    fMaterialsCombo->Resize(200, 20);
50    fMaterialsCombo->Associate(ActionFrame); 
51
52
53    
54 // text labels with material properties 
55    Text_t* labelText[8]  = 
56    {"Index             ", 
57     "Number of elements",
58     "Elements list     ",
59     "Atomic mass       ",
60     "Density           ", 
61     "State             ", 
62     "Radiation Length  ",
63     "Abs. Length       " }; 
64
65 // Entries for material properties
66    TGLayoutHints* lLayoutHints4   = 
67        new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
68    TGLayoutHints* lLayoutHints5 = 
69        new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
70    fMatSubframe2 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
71                 
72    { // local scope for i
73      for (Int_t i=0; i<8; i++) {
74        Int_t idT=i+1;   
75        fHframe[i] = new TGHorizontalFrame(fMatSubframe2, 500, 100, kFixedWidth);
76        fMatTextBuff[i] = new TGTextBuffer(200);
77        fMatTextEntry[i] = new TGTextEntry(fHframe[i], fMatTextBuff[i], 300);
78        fLabel[i] = new TGLabel(fHframe[i], labelText[i]);
79        fHframe[i]->AddFrame(fLabel[i], lLayoutHints5);
80        fHframe[i]->AddFrame(fMatTextEntry[i], lLayoutHints5);
81        fMatSubframe2->AddFrame(fHframe[i], lLayoutHints4);
82        fMatTextEntry[i]->Associate(ActionFrame);
83      }
84    } 
85
86 // making up Materials frame   
87      fCapFrame->AddFrame(fMatSubframe1,fMatFrameLayout);  
88      fCapFrame->AddFrame(fMatSubframe2,fMatFrameLayout);
89
90 // going to the main frame     
91      Parent->AddFrame(fCapFrame, fMatFrameLayout);   
92    
93 }
94
95 TG4MaterialsFrames::TG4MaterialsFrames(const TG4MaterialsFrames& mf) 
96 {
97 // Dummy copy constructor 
98   TG4Globals::Exception(
99     "Attempt to use TG4MaterialsFrames copy constructor.");
100 }
101
102 TG4MaterialsFrames& TG4MaterialsFrames::operator=(const TG4MaterialsFrames& mf)
103 {
104   // check assignement to self
105   if (this == &mf) return *this;
106
107   TG4Globals::Exception(
108     "Attempt to assign TG4MaterialsFrames singleton.");
109     
110   return *this;  
111 }    
112
113 TG4MaterialsFrames::~TG4MaterialsFrames()
114 {
115   //---> liquidator
116   
117    G4cout << "\n Now in  TG4MaterialsFrames destructor \n"<< G4endl;
118    delete fMatSubframe1;
119    delete fMatFrameLayout;
120    delete fMaterialsCombo;
121    delete fComboLabel;
122    delete fMatSubframe2;
123    delete fCapFrame;
124
125    Int_t i;
126    for (i=0; i<8; i++) {
127      delete fHframe[i];
128      delete fMatTextBuff[i];
129      delete fMatTextEntry[i];
130      delete fLabel[i];
131    }
132
133 }
134
135 void TG4MaterialsFrames::SetMaterialsComboEntries()
136 {
137 //---> puts names of materials into the combo box entries
138
139    const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
140
141     G4int ig = lComboEntries->entries();
142     G4String name;
143     
144     for (int ii=0; ii < ig; ii++)
145         { name = ((*lComboEntries )[ii])->GetName() ;
146           AddMaterialName( name, ii+1);
147         };
148
149     name = "  " ;
150     AddMaterialName( name, ig+1);
151                    
152 }
153
154 void TG4MaterialsFrames::AddMaterialName( const char* name, Int_t index) const
155 {
156   
157 //-----> adds a material name to the combo box  
158
159    fMaterialsCombo->AddEntry( name, index);
160    fMaterialsCombo->Select(index);
161    fMaterialsCombo->Resize(200, 20);
162 }
163
164 void TG4MaterialsFrames::DisplayMaterialCharacteristics()
165 {
166   
167 //-----> shows informations about materials listed in G4MaterialTable 
168
169    const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
170    G4int ientr = lComboEntries->entries();
171    G4int index = fMaterialsCombo->GetSelected();
172    
173    G4cout << "\nThe clicked-on material has the index:  " << index << G4endl;
174    
175    if( index < ientr+1 ) {
176    
177      G4int ii = index-1;
178      G4Material* lvMaterial = (*lComboEntries )[ii];
179      const G4ElementVector* allElements = lvMaterial->GetElementVector();
180
181      G4cout << lvMaterial->GetName() << "  "
182             << lvMaterial->GetNumberOfElements() << "  "
183             << (*allElements )[0]->GetName() << "...  "
184             << lvMaterial->GetDensity()/(g/cm3) << "  "
185             << lvMaterial->GetState() << "  "
186             << lvMaterial->GetRadlen()/(cm) << "  "
187             << G4endl;
188           
189    char buff[200];
190    
191     sprintf(buff, "%10i",index );
192     fMatTextBuff[0]->Clear();
193     fMatTextBuff[0]->AddText(0, buff);
194     gClient->NeedRedraw(fMatTextEntry[0]);
195     
196     G4int noe = lvMaterial->GetNumberOfElements();
197     sprintf(buff, "%10i", noe);
198     fMatTextBuff[1]->Clear();
199     fMatTextBuff[1]->AddText(0, buff);
200     gClient->NeedRedraw(fMatTextEntry[1]);
201
202     G4String stringOfElements = "  ";
203     for (G4int ie=0; ie < noe; ie++) {
204     stringOfElements += (*allElements )[ie]->GetName();
205     stringOfElements += "  ";
206     };
207     sprintf(buff, stringOfElements);
208     fMatTextBuff[2]->Clear();
209     fMatTextBuff[2]->AddText(0, buff);
210     gClient->NeedRedraw(fMatTextEntry[2]);
211
212     sprintf(buff, " Multi element material" );
213     if( noe < 2 )
214         sprintf(buff, "%10.2e", lvMaterial->GetA()/(g) );
215     fMatTextBuff[3]->Clear();
216     fMatTextBuff[3]->AddText(0, buff);
217     gClient->NeedRedraw(fMatTextEntry[3]);
218     
219     sprintf(buff, "%10.2e", lvMaterial->GetDensity()/(g/cm3) );
220     fMatTextBuff[4]->Clear();
221     fMatTextBuff[4]->AddText(0, buff);
222     gClient->NeedRedraw(fMatTextEntry[4]);
223     
224     sprintf(buff,"%10i", lvMaterial->GetState());
225     fMatTextBuff[5]->Clear();
226     fMatTextBuff[5]->AddText(0, buff);
227     gClient->NeedRedraw(fMatTextEntry[5]);
228     
229     sprintf(buff,"%10.2e", lvMaterial->GetRadlen()/(cm));
230     fMatTextBuff[6]->Clear();
231     fMatTextBuff[6]->AddText(0, buff);
232     gClient->NeedRedraw(fMatTextEntry[6]);
233     
234     sprintf(buff, "           " );
235     fMatTextBuff[7]->Clear();
236     fMatTextBuff[7]->AddText(0, buff);
237     gClient->NeedRedraw(fMatTextEntry[7]);
238     
239    };
240    
241    if( index == ientr+1 ) {
242    
243       for ( G4int ii=0; ii<8; ii++) {
244         fMatTextBuff[ii]->Clear();          
245         gClient->NeedRedraw(fMatTextEntry[ii]);
246         };
247      };      
248    
249 }
250