2 // Category: interfaces
6 //========================================================
8 //------------TG4VolumesFrames.cxx--------------------------------//
9 //--------- Frames for the the display of volumes properties---//
11 //=========================================================
13 #include "TG4VolumesFrames.h"
14 #include "TG4MaterialsFrames.h"
15 #include "TG4Editor.h"
16 #include "TG4Globals.h"
17 #include "TG4Limits.h"
18 #include "TG4G3CutVector.h"
21 #include <TGTextBuffer.h>
22 #include <TGTextEntry.h>
23 #include <TGComboBox.h>
26 //#include <TGFrame.h>
27 //#include <TGButton.h>
29 #include <G4LogicalVolumeStore.hh>
30 #include <G4LogicalVolume.hh>
31 #include <G4Material.hh>
32 #include <G4VSolid.hh>
33 #include <G4UserLimits.hh>
37 ClassImp(TG4VolumesFrames)
39 TG4VolumesFrames::TG4VolumesFrames( TGTab* Tab, TGMainFrame* ActionFrame)
41 //---> creates the volumes properties display frame
42 //---> and plunges it into the main frame
43 TGCompositeFrame* parent = Tab->AddTab("Volumes Properties");
44 fCapFrame = new TGCompositeFrame(parent, 60, 20, kHorizontalFrame);
45 ULong_t back= TGFrame::GetBlackPixel();
46 fCapFrame->ChangeBackground(back);
47 fVolSubframe1 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
48 fVolFrameLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
50 // ComboBox for lvolumes
51 fVolumesCombo = new TGComboBox(fVolSubframe1, 100);
52 TGLayoutHints* lLayoutHints3 =
53 new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
55 Text_t* lComboLabelText = " Pick up a volume here ";
56 fComboLabel = new TGLabel( fVolSubframe1, lComboLabelText);
57 fVolSubframe1->AddFrame(fComboLabel, lLayoutHints3);
58 fVolSubframe1->AddFrame(fVolumesCombo, fVolFrameLayout);
60 fVolumesCombo->Resize(200, 30);
61 fVolumesCombo->Associate(ActionFrame);
64 // text labels with lvolumes properties
66 Text_t* labelText[3] =
71 // Entries for lvolumes properties
72 TGLayoutHints* lLayoutHints4 =
73 new TGLayoutHints(kLHintsTop | kLHintsExpandY, 5, 5, 5, 5);
74 TGLayoutHints* lLayoutHints5 =
75 new TGLayoutHints(kLHintsLeft | kLHintsExpandX );
76 fVolSubframe2 = new TGCompositeFrame(fCapFrame, 60, 20, kVerticalFrame);
78 { // local scope for i
79 for (Int_t i=0; i<2; i++) {
81 fHframe[i] = new TGHorizontalFrame(fVolSubframe2, 500, 100, kFixedWidth);
82 fVolSubframe2->AddFrame(fHframe[i], lLayoutHints4);
83 fVolTextBuff[i] = new TGTextBuffer(200);
84 fVolTextEntry[i] = new TGTextEntry(fHframe[i], fVolTextBuff[i], 300);
85 fLabel[i] = new TGLabel(fHframe[i], labelText[i]);
86 fHframe[i]->AddFrame(fLabel[i], lLayoutHints5);
87 fHframe[i]->AddFrame(fVolTextEntry[i], lLayoutHints5);
88 fVolTextEntry[i]->Associate(ActionFrame);
92 // --->a group frame for displaying user's limits with a text entry added
95 new TGGroupFrame(fVolSubframe2, "----- User Limits Showcase -----", kVerticalFrame);
96 fHframe[2] = new TGHorizontalFrame( fGrFrame, 410, 100, kFixedWidth);
97 TGLayoutHints* lLayoutHints6 = new TGLayoutHints(kLHintsTop | kLHintsLeft ,
99 fLabel[2] = new TGLabel(fHframe[2], labelText[2]);
100 fHframe[2]->AddFrame(fLabel[2],lLayoutHints6);
101 fVolTextBuff[2] = new TGTextBuffer(200);
102 fVolTextEntry[2] = new TGTextEntry(fHframe[2], fVolTextBuff[2], 300);
103 fVolTextEntry[2]->Resize(1000, fVolTextEntry[2]->GetDefaultHeight());
104 fHframe[2]->AddFrame(fVolTextEntry[2], lLayoutHints6);
105 fVolTextEntry[2]->Associate(ActionFrame);
107 fGrFrame->AddFrame(fHframe[2], lLayoutHints4);
109 // ---> adding to the group frame another frame with text buttons
110 // for calling up a full display of user's limits properties
112 fGrHFrame= new TGHorizontalFrame( fGrFrame, 500, 100);
113 fbtsumm = new TGTextButton(fGrHFrame, "&User Limits", 301);
114 fbtcuts = new TGTextButton(fGrHFrame, "&Show Cuts", 302);
115 fbtcontrols = new TGTextButton(fGrHFrame, "&Show Controls", 303);
116 TGLayoutHints* lLayoutHints7 =
117 new TGLayoutHints(kLHintsTop | kLHintsLeft, 50, 0, 5, 5);
118 fGrHFrame->SetLayoutManager(new TGMatrixLayout(fGrHFrame, 0, 3, 15));
119 fGrHFrame->AddFrame( fbtsumm );
120 fbtsumm->Resize(90, fbtsumm->GetDefaultHeight());
121 fGrHFrame->AddFrame( fbtcuts );
122 fbtcuts->Resize(90, fbtcuts->GetDefaultHeight());
123 fGrHFrame->AddFrame( fbtcontrols );
124 fbtcontrols->Resize(90, fbtcontrols->GetDefaultHeight());
126 fbtsumm->Associate(ActionFrame);
127 fbtcuts->Associate(ActionFrame);
128 fbtcontrols->Associate(ActionFrame);
130 fGrFrame->AddFrame(fGrHFrame, lLayoutHints4);
132 //---> adding the group frame to the subrame 2
133 fVolSubframe2->AddFrame( fGrFrame, lLayoutHints7);
134 fGrFrame->Resize(fGrFrame->GetDefaultSize());
136 // ---> text for the user's limits display window when no volume specified yet
137 fDisplBuff = new TGTextBuffer(1000);
139 fDisplBuff->AddText(0, "\n\n*** No volume specified, "
140 "no limits displayed *** ");
143 // ---> making up the Volumes frame
144 fCapFrame->AddFrame(fVolSubframe1,fVolFrameLayout);
145 fCapFrame->AddFrame(fVolSubframe2,fVolFrameLayout);
147 // ---> going to the main frame
148 parent->AddFrame(fCapFrame, fVolFrameLayout);
150 SetPanel(ActionFrame);
154 TG4VolumesFrames::TG4VolumesFrames(const TG4VolumesFrames& vf)
156 // Dummy copy constructor
157 TG4Globals::Exception(
158 "Attempt to use TG4VolumesFrames copy constructor.");
161 TG4VolumesFrames& TG4VolumesFrames::operator=(const TG4VolumesFrames& vf)
163 // check assignement to self
164 if (this == &vf) return *this;
166 TG4Globals::Exception(
167 "Attempt to assign singleton.");
172 TG4VolumesFrames::~TG4VolumesFrames()
176 G4cout << "\n Now in TG4VolumesFrames destructor \n" << G4endl;
177 delete fVolSubframe1;
178 delete fVolFrameLayout;
179 delete fVolumesCombo;
181 delete fVolSubframe2;
190 for (i=0; i<3; i++) {
192 delete fVolTextBuff[i];
193 delete fVolTextEntry[i];
199 void TG4VolumesFrames::SetPanel(TGMainFrame* ActionFrame)
201 //---> produces the pointer to the main frame
203 fPanel = (TG4MainFrame*) ActionFrame;
206 void TG4VolumesFrames::SetVolumesComboEntries()
208 //--->//---> puts names of lvolumes into the combo box entries
210 G4LogicalVolumeStore* lComboEntries = G4LogicalVolumeStore::GetInstance();
212 G4int ig = lComboEntries->size();
215 for (int ii=0; ii < ig; ii++)
216 { name = ((*lComboEntries )[ii])->GetName() ;
217 AddLogicalVolumeName( name, ii+1);
221 AddLogicalVolumeName( name, ig+1);
226 void TG4VolumesFrames::AddLogicalVolumeName( const char* name, Int_t index) const
228 //-----> adds an lvolume name to the combo box
230 fVolumesCombo->AddEntry( name, index);
231 fVolumesCombo->Select(index);
232 fVolumesCombo->Resize(200, 20);
235 void TG4VolumesFrames::DisplayVolumeCharacteristics()
237 //-----> shows informations about a logical volume
239 G4LogicalVolumeStore* lComboEntries = G4LogicalVolumeStore::GetInstance();
240 G4int ientr = lComboEntries->size();
241 G4int index = fVolumesCombo->GetSelected();
244 G4cout << "\nThe clicked-on volumes entry has the index: " << index << G4endl;
248 if( index < ientr+1 ) {
251 G4LogicalVolume* lVolume = (*lComboEntries )[ii];
252 G4Material* lvMaterial = ((*lComboEntries )[ii])->GetMaterial();
253 lLimits = (TG4Limits*)lVolume->GetUserLimits();
254 TString lDisplayLimits = GetDisplay(lLimits);
256 //---> fills up the buffer for popup frame display
258 fDisplBuff->AddText(0,lDisplayLimits);
260 G4cout << lVolume->GetName() << " "
261 << lVolume->GetSolid()->GetEntityType() << " "
262 << lvMaterial->GetName() << " "
263 << lVolume->GetUserLimits()->GetType() << G4endl;
265 //---> putting text in the text entries
268 sprintf(buff, lVolume->GetSolid()->GetEntityType());
269 fVolTextBuff[0]->Clear();
270 fVolTextBuff[0]->AddText(0, buff);
271 gClient->NeedRedraw(fVolTextEntry[0]);
273 sprintf(buff, lvMaterial->GetName());
274 fVolTextBuff[1]->Clear();
275 fVolTextBuff[1]->AddText(0, buff);
276 gClient->NeedRedraw(fVolTextEntry[1]);
279 sprintf(buff, "User limits undefined" );
280 if (lVolume->GetUserLimits())
281 sprintf(buff, lLimits->GetName());
282 fVolTextBuff[2]->Clear();
283 fVolTextBuff[2]->AddText(0, buff);
284 gClient->NeedRedraw(fVolTextEntry[2]);
286 imat = lvMaterial->GetIndex();
290 if( index == ientr+1 ) {
292 for ( G4int ii=0; ii<3; ii++) {
293 fVolTextBuff[ii]->Clear();
294 gClient->NeedRedraw(fVolTextEntry[ii]);
297 fDisplBuff->AddText(0, "\n\n*** No volume specified, "
298 "no limits displayed *** ");
302 //---> setting appropriate display in the MaterialsFrames
303 TG4MaterialsFrames* mFrames = fPanel->GetMaterialsFrames();
304 mFrames->DisplayMaterialCharacteristics( imat + 1 );
308 void TG4VolumesFrames::DisplayUserLimits()
310 //-----> displays User Limits associated with the logical volume
312 const char* cdisplay = fDisplBuff->GetString();
313 TG4Editor* ed = new TG4Editor( fCapFrame, 450, 300);
314 ed->LoadBuffer(cdisplay);
319 TString TG4VolumesFrames::GetDisplay(G4UserLimits* limits) const
321 // Returns text for the user limits display in a separate frame
327 display = "\n\n**************************************";
328 display += "\n**************************************\n\n";
330 display += ((TG4Limits*)limits)->GetName();
331 display += "\" limits:";
332 display += "\n\n Max step length (mm): ";
333 TG4Globals::AppendNumberToString( display, limits->GetMaxAllowedStep(dummy)/mm);
334 // sprintf(buff, "%12.5e", fMaxStep/mm );
336 display += "\n\n Max track length (mm): ";
337 sprintf(buff, "%12.5e", limits->GetUserMaxTrackLength(dummy)/mm );
339 display += "\n\n Max time (s) : ";
340 sprintf(buff, "%12.5e", limits->GetUserMaxTime(dummy)/s );
342 display += "\n\n Min kin. energy (MeV): ";
343 TG4Globals::AppendNumberToString( display, limits->GetUserMinEkine(dummy)/MeV);
344 // sprintf(buff, "%12.5e", fMinEkine/MeV );
346 display += "\n\n Min range (mm): " ;
347 TG4Globals::AppendNumberToString( display, limits->GetUserMinRange(dummy)/mm);
348 // sprintf(buff, "%12.5e", fMinRange/mm);
350 display += "\n\n**************************************";
351 display += "\n**************************************\n\n";
353 const char* tmp = display;