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>
21 #include <G4Material.hh>
22 #include <G4Element.hh>
26 ClassImp(TG4MaterialsFrames)
28 TG4MaterialsFrames::TG4MaterialsFrames( TGCompositeFrame* Parent, TGMainFrame* ActionFrame )
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);
38 // ComboBox for materials
39 fMaterialsCombo = new TGComboBox(fMatSubframe1, 200);
40 TGLayoutHints* lLayoutHints3 =
41 new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
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);
49 fMaterialsCombo->Resize(200, 20);
50 fMaterialsCombo->Associate(ActionFrame);
54 // text labels with material properties
55 Text_t* labelText[8] =
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);
72 { // local scope for i
73 for (Int_t i=0; i<8; i++) {
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);
86 // making up Materials frame
87 fCapFrame->AddFrame(fMatSubframe1,fMatFrameLayout);
88 fCapFrame->AddFrame(fMatSubframe2,fMatFrameLayout);
90 // going to the main frame
91 Parent->AddFrame(fCapFrame, fMatFrameLayout);
95 TG4MaterialsFrames::TG4MaterialsFrames(const TG4MaterialsFrames& mf)
97 // Dummy copy constructor
98 TG4Globals::Exception(
99 "Attempt to use TG4MaterialsFrames copy constructor.");
102 TG4MaterialsFrames& TG4MaterialsFrames::operator=(const TG4MaterialsFrames& mf)
104 // check assignement to self
105 if (this == &mf) return *this;
107 TG4Globals::Exception(
108 "Attempt to assign TG4MaterialsFrames singleton.");
113 TG4MaterialsFrames::~TG4MaterialsFrames()
117 G4cout << "\n Now in TG4MaterialsFrames destructor \n"<< G4endl;
118 delete fMatSubframe1;
119 delete fMatFrameLayout;
120 delete fMaterialsCombo;
122 delete fMatSubframe2;
126 for (i=0; i<8; i++) {
128 delete fMatTextBuff[i];
129 delete fMatTextEntry[i];
135 void TG4MaterialsFrames::SetMaterialsComboEntries()
137 //---> puts names of materials into the combo box entries
139 const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
141 G4int ig = lComboEntries->entries();
144 for (int ii=0; ii < ig; ii++)
145 { name = ((*lComboEntries )[ii])->GetName() ;
146 AddMaterialName( name, ii+1);
150 AddMaterialName( name, ig+1);
154 void TG4MaterialsFrames::AddMaterialName( const char* name, Int_t index) const
157 //-----> adds a material name to the combo box
159 fMaterialsCombo->AddEntry( name, index);
160 fMaterialsCombo->Select(index);
161 fMaterialsCombo->Resize(200, 20);
164 void TG4MaterialsFrames::DisplayMaterialCharacteristics()
167 //-----> shows informations about materials listed in G4MaterialTable
169 const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
170 G4int ientr = lComboEntries->entries();
171 G4int index = fMaterialsCombo->GetSelected();
173 G4cout << "\nThe clicked-on material has the index: " << index << G4endl;
175 if( index < ientr+1 ) {
178 G4Material* lvMaterial = (*lComboEntries )[ii];
179 const G4ElementVector* allElements = lvMaterial->GetElementVector();
181 G4cout << lvMaterial->GetName() << " "
182 << lvMaterial->GetNumberOfElements() << " "
183 << (*allElements )[0]->GetName() << "... "
184 << lvMaterial->GetDensity()/(g/cm3) << " "
185 << lvMaterial->GetState() << " "
186 << lvMaterial->GetRadlen()/(cm) << " "
191 sprintf(buff, "%10i",index );
192 fMatTextBuff[0]->Clear();
193 fMatTextBuff[0]->AddText(0, buff);
194 gClient->NeedRedraw(fMatTextEntry[0]);
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]);
202 G4String stringOfElements = " ";
203 for (G4int ie=0; ie < noe; ie++) {
204 stringOfElements += (*allElements )[ie]->GetName();
205 stringOfElements += " ";
207 sprintf(buff, stringOfElements);
208 fMatTextBuff[2]->Clear();
209 fMatTextBuff[2]->AddText(0, buff);
210 gClient->NeedRedraw(fMatTextEntry[2]);
212 sprintf(buff, " Multi element material" );
214 sprintf(buff, "%10.2e", lvMaterial->GetA()/(g) );
215 fMatTextBuff[3]->Clear();
216 fMatTextBuff[3]->AddText(0, buff);
217 gClient->NeedRedraw(fMatTextEntry[3]);
219 sprintf(buff, "%10.2e", lvMaterial->GetDensity()/(g/cm3) );
220 fMatTextBuff[4]->Clear();
221 fMatTextBuff[4]->AddText(0, buff);
222 gClient->NeedRedraw(fMatTextEntry[4]);
224 sprintf(buff,"%10i", lvMaterial->GetState());
225 fMatTextBuff[5]->Clear();
226 fMatTextBuff[5]->AddText(0, buff);
227 gClient->NeedRedraw(fMatTextEntry[5]);
229 sprintf(buff,"%10.2e", lvMaterial->GetRadlen()/(cm));
230 fMatTextBuff[6]->Clear();
231 fMatTextBuff[6]->AddText(0, buff);
232 gClient->NeedRedraw(fMatTextEntry[6]);
235 fMatTextBuff[7]->Clear();
236 fMatTextBuff[7]->AddText(0, buff);
237 gClient->NeedRedraw(fMatTextEntry[7]);
241 if( index == ientr+1 ) {
243 for ( G4int ii=0; ii<8; ii++) {
244 fMatTextBuff[ii]->Clear();
245 gClient->NeedRedraw(fMatTextEntry[ii]);