2 // Category: interfaces
6 //========================================================
8 //------------TG4MaterialsFrames.cxx--------------------------------//
9 //--------- Frames for the the display of materials properties---//
11 //=========================================================
13 #include "TG4MaterialsFrames.h"
14 #include "TG4Globals.h"
16 #include <TGTextBuffer.h>
17 #include <TGTextEntry.h>
18 #include <TGComboBox.h>
22 #include <G4Material.hh>
23 #include <G4Element.hh>
27 ClassImp(TG4MaterialsFrames)
29 TG4MaterialsFrames::TG4MaterialsFrames( TGTab* Tab, TGMainFrame* ActionFrame )
31 //---> creates the materials properties display frame
32 //---> and plunges it into the main frame
33 TGCompositeFrame* parent = Tab->AddTab("Materials Properties");
34 fCapFrame = new TGCompositeFrame(parent, 60, 20, kHorizontalFrame);
35 ULong_t back= TGFrame::GetBlackPixel();
36 fCapFrame->ChangeBackground(back);
37 fMatSubframe1 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
38 fMatFrameLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
40 // ComboBox for materials
41 fMaterialsCombo = new TGComboBox(fMatSubframe1, 200);
42 TGLayoutHints* lLayoutHints3 =
43 new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
45 Text_t* lComboLabelText = " Pick up a material here ";
46 fComboLabel = new TGLabel( fMatSubframe1, lComboLabelText);
47 fMatSubframe1->AddFrame(fComboLabel, lLayoutHints3);
48 fMatSubframe1->AddFrame(fMaterialsCombo, fMatFrameLayout);
51 fMaterialsCombo->Resize(200, 20);
52 fMaterialsCombo->Associate(ActionFrame);
56 // text labels with material properties
57 Text_t* labelText[8] =
67 // Entries for material properties
68 TGLayoutHints* lLayoutHints4 =
69 new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
70 TGLayoutHints* lLayoutHints5 =
71 new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
72 fMatSubframe2 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
74 { // local scope for i
75 for (Int_t i=0; i<8; i++) {
77 fHframe[i] = new TGHorizontalFrame(fMatSubframe2, 500, 100, kFixedWidth);
78 fMatTextBuff[i] = new TGTextBuffer(200);
79 fMatTextEntry[i] = new TGTextEntry(fHframe[i], fMatTextBuff[i], 300);
80 fLabel[i] = new TGLabel(fHframe[i], labelText[i]);
81 fHframe[i]->AddFrame(fLabel[i], lLayoutHints5);
82 fHframe[i]->AddFrame(fMatTextEntry[i], lLayoutHints5);
83 fMatSubframe2->AddFrame(fHframe[i], lLayoutHints4);
84 fMatTextEntry[i]->Associate(ActionFrame);
88 // making up Materials frame
89 fCapFrame->AddFrame(fMatSubframe1,fMatFrameLayout);
90 fCapFrame->AddFrame(fMatSubframe2,fMatFrameLayout);
92 // going to the main frame
93 parent->AddFrame(fCapFrame, fMatFrameLayout);
97 TG4MaterialsFrames::TG4MaterialsFrames(const TG4MaterialsFrames& mf)
99 // Dummy copy constructor
100 TG4Globals::Exception(
101 "Attempt to use TG4MaterialsFrames copy constructor.");
104 TG4MaterialsFrames& TG4MaterialsFrames::operator=(const TG4MaterialsFrames& mf)
106 // check assignement to self
107 if (this == &mf) return *this;
109 TG4Globals::Exception(
110 "Attempt to assign TG4MaterialsFrames singleton.");
115 TG4MaterialsFrames::~TG4MaterialsFrames()
119 G4cout << "\n Now in TG4MaterialsFrames destructor \n"<< G4endl;
120 delete fMatSubframe1;
121 delete fMatFrameLayout;
122 delete fMaterialsCombo;
124 delete fMatSubframe2;
128 for (i=0; i<8; i++) {
130 delete fMatTextBuff[i];
131 delete fMatTextEntry[i];
137 void TG4MaterialsFrames::SetMaterialsComboEntries()
139 //---> puts names of materials into the combo box entries
141 const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
143 G4int ig = lComboEntries->entries();
146 for (int ii=0; ii < ig; ii++)
147 { name = ((*lComboEntries )[ii])->GetName() ;
148 AddMaterialName( name, ii+1);
152 AddMaterialName( name, ig+1);
156 void TG4MaterialsFrames::AddMaterialName( const char* name, Int_t index) const
159 //-----> adds a material name to the combo box
161 fMaterialsCombo->AddEntry( name, index);
162 fMaterialsCombo->Select(index);
163 fMaterialsCombo->Resize(200, 20);
166 void TG4MaterialsFrames::DisplayMaterialCharacteristics()
169 //-----> shows informations about materials listed in G4MaterialTable
171 const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
172 G4int ientr = lComboEntries->entries();
173 G4int index = fMaterialsCombo->GetSelected();
175 G4cout << "\nThe clicked-on material has the index: " << index << G4endl;
177 if( index < ientr+1 ) {
180 G4Material* lvMaterial = (*lComboEntries )[ii];
181 const G4ElementVector* allElements = lvMaterial->GetElementVector();
183 G4cout << lvMaterial->GetName() << " "
184 << lvMaterial->GetNumberOfElements() << " "
185 << (*allElements )[0]->GetName() << "... "
186 << lvMaterial->GetDensity()/(g/cm3) << " "
187 << lvMaterial->GetState() << " "
188 << lvMaterial->GetRadlen()/(cm) << " "
193 sprintf(buff, "%10i",index );
194 fMatTextBuff[0]->Clear();
195 fMatTextBuff[0]->AddText(0, buff);
196 gClient->NeedRedraw(fMatTextEntry[0]);
198 G4int noe = lvMaterial->GetNumberOfElements();
199 sprintf(buff, "%10i", noe);
200 fMatTextBuff[1]->Clear();
201 fMatTextBuff[1]->AddText(0, buff);
202 gClient->NeedRedraw(fMatTextEntry[1]);
204 G4String stringOfElements = " ";
205 for (G4int ie=0; ie < noe; ie++) {
206 stringOfElements += (*allElements )[ie]->GetName();
207 stringOfElements += " ";
209 sprintf(buff, stringOfElements);
210 fMatTextBuff[2]->Clear();
211 fMatTextBuff[2]->AddText(0, buff);
212 gClient->NeedRedraw(fMatTextEntry[2]);
214 sprintf(buff, " Multi element material" );
216 sprintf(buff, "%10.2e", lvMaterial->GetA()/(g) );
217 fMatTextBuff[3]->Clear();
218 fMatTextBuff[3]->AddText(0, buff);
219 gClient->NeedRedraw(fMatTextEntry[3]);
221 sprintf(buff, "%10.2e", lvMaterial->GetDensity()/(g/cm3) );
222 fMatTextBuff[4]->Clear();
223 fMatTextBuff[4]->AddText(0, buff);
224 gClient->NeedRedraw(fMatTextEntry[4]);
226 sprintf(buff,"%10i", lvMaterial->GetState());
227 fMatTextBuff[5]->Clear();
228 fMatTextBuff[5]->AddText(0, buff);
229 gClient->NeedRedraw(fMatTextEntry[5]);
231 sprintf(buff,"%10.2e", lvMaterial->GetRadlen()/(cm));
232 fMatTextBuff[6]->Clear();
233 fMatTextBuff[6]->AddText(0, buff);
234 gClient->NeedRedraw(fMatTextEntry[6]);
237 fMatTextBuff[7]->Clear();
238 fMatTextBuff[7]->AddText(0, buff);
239 gClient->NeedRedraw(fMatTextEntry[7]);
243 if( index == ientr+1 ) {
245 for ( G4int ii=0; ii<8; ii++) {
246 fMatTextBuff[ii]->Clear();
247 gClient->NeedRedraw(fMatTextEntry[ii]);