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 fMatSubframe1 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
34 fMatFrameLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
36 // ComboBox for materials
37 fMaterialsCombo = new TGComboBox(fMatSubframe1, 200);
38 TGLayoutHints* lLayoutHints3 =
39 new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
41 Text_t* lComboLabelText = " Pick up a material here ";
42 fComboLabel = new TGLabel( fMatSubframe1, lComboLabelText);
43 fMatSubframe1->AddFrame(fComboLabel, lLayoutHints3);
44 fMatSubframe1->AddFrame(fMaterialsCombo, fMatFrameLayout);
47 fMaterialsCombo->Resize(200, 20);
48 fMaterialsCombo->Associate(ActionFrame);
52 // text labels with material properties
53 Text_t* labelText[8] =
63 // Entries for material properties
64 TGLayoutHints* lLayoutHints4 =
65 new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
66 TGLayoutHints* lLayoutHints5 =
67 new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
68 fMatSubframe2 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
70 { // local scope for i
71 for (Int_t i=0; i<8; i++) {
73 fHframe[i] = new TGHorizontalFrame(fMatSubframe2, 500, 100, kFixedWidth);
74 fMatTextBuff[i] = new TGTextBuffer(200);
75 fMatTextEntry[i] = new TGTextEntry(fHframe[i], fMatTextBuff[i], 300);
76 fLabel[i] = new TGLabel(fHframe[i], labelText[i]);
77 fHframe[i]->AddFrame(fLabel[i], lLayoutHints5);
78 fHframe[i]->AddFrame(fMatTextEntry[i], lLayoutHints5);
79 fMatSubframe2->AddFrame(fHframe[i], lLayoutHints4);
80 fMatTextEntry[i]->Associate(ActionFrame);
84 // making up Materials frame
85 fCapFrame->AddFrame(fMatSubframe1,fMatFrameLayout);
86 fCapFrame->AddFrame(fMatSubframe2,fMatFrameLayout);
88 // going to the main frame
89 Parent->AddFrame(fCapFrame, fMatFrameLayout);
93 TG4MaterialsFrames::TG4MaterialsFrames(const TG4MaterialsFrames& mf)
95 // Dummy copy constructor
96 TG4Globals::Exception(
97 "Attempt to use TG4MaterialsFrames copy constructor.");
100 TG4MaterialsFrames& TG4MaterialsFrames::operator=(const TG4MaterialsFrames& mf)
102 // check assignement to self
103 if (this == &mf) return *this;
105 TG4Globals::Exception(
106 "Attempt to assign TG4MaterialsFrames singleton.");
111 TG4MaterialsFrames::~TG4MaterialsFrames()
115 G4cout << "\n Now in TG4MaterialsFrames destructor \n"<< G4endl;
116 delete fMatSubframe1;
117 delete fMatFrameLayout;
118 delete fMaterialsCombo;
120 delete fMatSubframe2;
124 for (i=0; i<8; i++) {
126 delete fMatTextBuff[i];
127 delete fMatTextEntry[i];
133 void TG4MaterialsFrames::SetMaterialsComboEntries()
135 //---> puts names of materials into the combo box entries
137 const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
139 G4int ig = lComboEntries->entries();
142 for (int ii=0; ii < ig; ii++)
143 { name = ((*lComboEntries )[ii])->GetName() ;
144 AddMaterialName( name, ii+1);
148 AddMaterialName( name, ig+1);
152 void TG4MaterialsFrames::AddMaterialName( const char* name, Int_t index) const
155 //-----> adds a material name to the combo box
157 fMaterialsCombo->AddEntry( name, index);
158 fMaterialsCombo->Select(index);
159 fMaterialsCombo->Resize(200, 20);
162 void TG4MaterialsFrames::DisplayMaterialCharacteristics()
165 //-----> shows informations about materials listed in G4MaterialTable
167 const G4MaterialTable* lComboEntries = G4Material::GetMaterialTable();
168 G4int ientr = lComboEntries->entries();
169 G4int index = fMaterialsCombo->GetSelected();
171 G4cout << "\nThe clicked-on material has the index: " << index << G4endl;
173 if( index < ientr+1 ) {
176 G4Material* lvMaterial = (*lComboEntries )[ii];
177 const G4ElementVector* allElements = lvMaterial->GetElementVector();
179 G4cout << lvMaterial->GetName() << " "
180 << lvMaterial->GetNumberOfElements() << " "
181 << (*allElements )[0]->GetName() << "... "
182 << lvMaterial->GetDensity() << " "
183 << lvMaterial->GetState() << " "
184 << lvMaterial->GetRadlen() << " "
189 sprintf(buff, "%10i",index );
190 fMatTextBuff[0]->Clear();
191 fMatTextBuff[0]->AddText(0, buff);
192 gClient->NeedRedraw(fMatTextEntry[0]);
194 G4int noe = lvMaterial->GetNumberOfElements();
195 sprintf(buff, "%10i", noe);
196 fMatTextBuff[1]->Clear();
197 fMatTextBuff[1]->AddText(0, buff);
198 gClient->NeedRedraw(fMatTextEntry[1]);
200 G4String stringOfElements = " ";
201 for (G4int ie=0; ie < noe; ie++) {
202 stringOfElements += (*allElements )[ie]->GetName();
203 stringOfElements += " ";
205 sprintf(buff, stringOfElements);
206 fMatTextBuff[2]->Clear();
207 fMatTextBuff[2]->AddText(0, buff);
208 gClient->NeedRedraw(fMatTextEntry[2]);
210 sprintf(buff, " Multi element material" );
212 sprintf(buff, "%10.2e", lvMaterial->GetA() );
213 fMatTextBuff[3]->Clear();
214 fMatTextBuff[3]->AddText(0, buff);
215 gClient->NeedRedraw(fMatTextEntry[3]);
217 sprintf(buff, "%10.2e", lvMaterial->GetDensity() );
218 fMatTextBuff[4]->Clear();
219 fMatTextBuff[4]->AddText(0, buff);
220 gClient->NeedRedraw(fMatTextEntry[4]);
222 sprintf(buff,"%10i", lvMaterial->GetState());
223 fMatTextBuff[5]->Clear();
224 fMatTextBuff[5]->AddText(0, buff);
225 gClient->NeedRedraw(fMatTextEntry[5]);
227 sprintf(buff,"%10.2e", lvMaterial->GetRadlen());
228 fMatTextBuff[6]->Clear();
229 fMatTextBuff[6]->AddText(0, buff);
230 gClient->NeedRedraw(fMatTextEntry[6]);
233 fMatTextBuff[7]->Clear();
234 fMatTextBuff[7]->AddText(0, buff);
235 gClient->NeedRedraw(fMatTextEntry[7]);
239 if( index == ientr+1 ) {
241 for ( G4int ii=0; ii<8; ii++) {
242 fMatTextBuff[ii]->Clear();
243 gClient->NeedRedraw(fMatTextEntry[ii]);