source: trunk/source/geometry/solids/test/fred/src/FredMessenger.cc @ 1316

Last change on this file since 1316 was 1316, checked in by garnier, 14 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 9.9 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// FredMessenger.cc
28//
29// Implementation of fred's (primary) options
30//
31
32#include "FredMessenger.hh"
33#include "FredTest3Messenger.hh"
34#include "FredVoxelTestMessenger.hh"
35
36#include "G4UIdirectory.hh"
37#include "G4UIcmdWithAString.hh"
38#include "G4UIcmdWithADouble.hh"
39#include "G4UIcmdWithoutParameter.hh"
40#include "G4UIcmdWithAnInteger.hh"
41#include "G4ios.hh"
42
43//
44// Constructor
45//
46FredMessenger::FredMessenger( )
47{
48        testVolume = 0;
49
50        volumeNames[NATALIA] = "NATALIA";       // Yeah, yeah. Really cheezy, I know
51        volumeNames[VOXEL]   = "VOXEL";
52
53        volumeNames[BOX]     = "BOX";
54        volumeNames[CONE]    = "CONE";
55        volumeNames[CONE2]   = "CONE2";
56        volumeNames[ORB]     = "ORB";
57        volumeNames[PARA]    = "PARA";
58        volumeNames[SPHERE]  = "SPHERE";
59        volumeNames[TORUS1]  = "TORUS1";
60        volumeNames[TORUS2]  = "TORUS2";
61        volumeNames[TRAP]    = "TRAP";
62        volumeNames[TRD]     = "TRD";
63        volumeNames[TUBS]    = "TUBS";
64
65        volumeNames[ELLIPS]  = "ELLIPS";
66        volumeNames[ELCONE]  = "ELCONE";
67        volumeNames[ELTUBE]  = "ELTUBE";
68        volumeNames[EXTRU1]  = "EXTRU1";
69        volumeNames[EXTRU2]  = "EXTRU2";
70        volumeNames[EXTRU3]  = "EXTRU3";
71        volumeNames[EXTRU4]  = "EXTRU4";
72        volumeNames[HYPE]    = "HYPE";
73        volumeNames[PCON]    = "PCON";
74        volumeNames[PCON2]   = "PCON2";
75        volumeNames[PCON3]   = "PCON3";
76        volumeNames[PCON4]   = "PCON4";
77        volumeNames[PGON]    = "PGON";
78        volumeNames[PGON2]   = "PGON2";
79        volumeNames[PGON3]   = "PGON3";
80        volumeNames[TESSEL1] = "TESSEL1";
81        volumeNames[TESSEL2] = "TESSEL2";
82        volumeNames[TESSEL3] = "TESSEL3";
83        volumeNames[TESSEL4] = "TESSEL4";
84        volumeNames[TET]     = "TET";
85        volumeNames[TWBOX]   = "TWBOX";
86        volumeNames[TWTRAP1] = "TWTRAP1";
87        volumeNames[TWTRAP2] = "TWTRAP2";
88        volumeNames[TWTRD]   = "TWTRD";
89        volumeNames[TWTUBS]  = "TWTUBS";
90
91        volumeNames[BOOL1]  =  "BOOL1";
92
93        gunNames[SPRAY] = "SPRAY";
94        gunNames[GRID]  = "GRID";
95        gunNames[G4]    = "G4";
96
97        drawNames[NORMAL] = "NORMAL";
98        drawNames[SHADOW] = "SHADOW";
99
100        //
101        // Defaults
102        //
103        testVolumeType = BOX;
104        gunType = SPRAY;
105        drawType = NORMAL;
106       
107        startPhi = 0;
108        deltaPhi = 360;
109       
110        numSide = 8;
111       
112        //
113        // Declare directory
114        //
115        fredDirectory = new G4UIdirectory( "/fred/" );
116        fredDirectory->SetGuidance( "Fred's options" );
117       
118        //
119        // Volume command
120        //
121        volumeTypeNameCmd = new G4UIcmdWithAString( "/fred/volume", this );
122        volumeTypeNameCmd->SetGuidance( "Test Volume Type" );
123        volumeTypeNameCmd->SetParameterName( "VolumeType", true );
124       
125        G4String choices = volumeNames[NATALIA] + " "
126                         + volumeNames[VOXEL] + " "
127                         + volumeNames[BOX]  + " "
128                         + volumeNames[CONE] + " "
129                         + volumeNames[CONE2] + " "
130                         + volumeNames[ORB] + " "
131                         + volumeNames[PARA] + " "
132                         + volumeNames[SPHERE] + " "
133                         + volumeNames[TORUS1] + " "
134                         + volumeNames[TORUS2] + " "
135                         + volumeNames[TRAP] + " "
136                         + volumeNames[TRD] + " "
137                         + volumeNames[TUBS] + " "
138                         + volumeNames[ELLIPS] + " " 
139                         + volumeNames[ELCONE] + " " 
140                         + volumeNames[ELTUBE] + " " 
141                         + volumeNames[EXTRU1] + " " 
142                         + volumeNames[EXTRU2] + " " 
143                         + volumeNames[EXTRU3] + " " 
144                         + volumeNames[EXTRU4] + " " 
145                         + volumeNames[HYPE] + " " 
146                         + volumeNames[PCON] + " "
147                         + volumeNames[PCON2] + " "
148                         + volumeNames[PCON3] + " "
149                         + volumeNames[PCON4] + " "
150                         + volumeNames[PGON] + " "
151                         + volumeNames[PGON2] + " "
152                         + volumeNames[PGON3] + " "
153                         + volumeNames[TESSEL1] + " " 
154                         + volumeNames[TESSEL2] + " " 
155                         + volumeNames[TESSEL3] + " " 
156                         + volumeNames[TESSEL4] + " " 
157                         + volumeNames[TET] + " " 
158                         + volumeNames[TWBOX] + " " 
159                         + volumeNames[TWTRAP1] + " " 
160                         + volumeNames[TWTRAP2] + " " 
161                         + volumeNames[TWTRD] + " " 
162                         + volumeNames[TWTUBS] + " " 
163                         + volumeNames[BOOL1];
164        volumeTypeNameCmd->SetCandidates( choices );
165       
166        volumeTypeNameCmd->AvailableForStates( G4State_PreInit, G4State_Idle );
167       
168        //
169        // gun command
170        //
171        gunTypeNameCmd = new G4UIcmdWithAString( "/fred/gun", this );
172        gunTypeNameCmd->SetGuidance( "Type of particle gun to use" );
173        gunTypeNameCmd->SetParameterName( "GunType", true );
174       
175        G4String choices2 = gunNames[SPRAY] + " "
176                          + gunNames[GRID] + " "
177                          + gunNames[G4];
178        gunTypeNameCmd->SetCandidates( choices2 );
179       
180        //
181        // draw command
182        //
183        drawTypeNameCmd = new G4UIcmdWithAString( "/fred/draw", this );
184        drawTypeNameCmd->SetGuidance( "Type of drawing to make" );
185        drawTypeNameCmd->SetParameterName( "DrawType", true );
186       
187        G4String choices3 = drawNames[NORMAL] + " "
188                          + drawNames[SHADOW];
189        drawTypeNameCmd->SetCandidates( choices3 );
190       
191        //
192        // Start Phi Command
193        //
194        startPhiCmd = new G4UIcmdWithADouble( "/fred/startPhi", this );
195        startPhiCmd->SetGuidance( "Starting phi value (degrees) for test volume" );
196        startPhiCmd->SetParameterName( "StartPhi", true );
197        startPhiCmd->AvailableForStates( G4State_PreInit, G4State_Idle );
198       
199        //
200        // Delta Phi Command
201        //
202        deltaPhiCmd = new G4UIcmdWithADouble( "/fred/deltaPhi", this );
203        deltaPhiCmd->SetGuidance( "Delta phi value (degrees) for test volume" );
204        deltaPhiCmd->SetParameterName( "DeltaPhi", true );
205        deltaPhiCmd->AvailableForStates( G4State_PreInit, G4State_Idle );
206       
207        //
208        // Number sides command
209        //
210        numSideCmd = new G4UIcmdWithAnInteger( "/fred/numSide", this );
211        numSideCmd->SetGuidance( "Number phi segments for test volume" );
212        numSideCmd->SetParameterName( "NumberSide", true );
213        numSideCmd->AvailableForStates( G4State_PreInit, G4State_Idle );
214
215        //
216        // Pause command
217        //
218        pauseCmd = new G4UIcmdWithoutParameter( "/fred/pause", this );
219        pauseCmd->SetGuidance( "Prompts for return" );
220        pauseCmd->AvailableForStates( G4State_PreInit, G4State_Idle );
221       
222        //
223        // Declare test3 messenger
224        //
225        test3Messenger = new FredTest3Messenger();
226       
227        //
228        // Declare voxel test messenger
229        //
230        voxelTestMessenger = new FredVoxelTestMessenger();
231}
232
233//
234// Destructor
235//
236FredMessenger::~FredMessenger() 
237{
238        delete test3Messenger;
239        delete voxelTestMessenger;
240        delete volumeTypeNameCmd;
241        delete fredDirectory;
242}
243
244
245//
246// SetTestVolume
247//
248// Set the target volume for test 3. We need to funnel this down
249// to our test 3 messenger
250//
251void FredMessenger::SetTestVolume( const G4VSolid *theTestVolume )
252{
253        testVolume = theTestVolume;
254        test3Messenger->SetTestVolume( testVolume );
255        voxelTestMessenger->SetTestVolume( testVolume );
256}
257
258
259//
260// SelectedVolume
261//
262// Return selected test volume type
263//
264VolumeType FredMessenger::SelectedVolume()
265{
266        return(testVolumeType);
267}
268
269//
270// SelectedGun
271//
272// Return selected gun
273//
274GunType FredMessenger::SelectedGun()
275{
276        return(gunType);
277}
278
279//
280// SelectedDrawing
281//
282// Return selected drawing type
283//
284DrawType FredMessenger::SelectedDrawing()
285{
286        return( drawType );
287}
288
289
290//
291// PauseInput
292//
293// This is to make up for a deficiency in the basic user-inteface:
294// Wait for input from the user
295//
296void FredMessenger::PauseInput()
297{
298        G4cout << "Press <return> to continue: " << std::flush;
299        char c;
300        G4cin.get(c);
301}
302
303
304//
305// SetNewValue
306//
307void FredMessenger::SetNewValue( G4UIcommand *command, G4String newValues )
308{
309        if (command == volumeTypeNameCmd) {
310                for( G4int vol = 0; vol < FRED_VOLUMETYPE_NUM; vol++ ) {
311                        if (volumeNames[vol] == newValues) {
312                                testVolumeType = (VolumeType)vol;
313                                break;
314                        }
315                }
316        }
317        else if (command == gunTypeNameCmd) {
318                for( G4int gun = 0; gun < FRED_GUNTYPE_NUM; gun++ ) {
319                        if (gunNames[gun] == newValues) {
320                                gunType = (GunType)gun;
321                                break;
322                        }
323                }
324        }
325        else if (command == drawTypeNameCmd) {
326                for( G4int draw = 0; draw < FRED_DRAWTYPE_NUM; draw++ ) {
327                        if (drawNames[draw] == newValues) {
328                                drawType = (DrawType)draw;
329                                break;
330                        }
331                }
332        }
333        else if (command == startPhiCmd) {
334                startPhi = startPhiCmd->GetNewDoubleValue( newValues );
335        }
336        else if (command == deltaPhiCmd) {
337                deltaPhi = deltaPhiCmd->GetNewDoubleValue( newValues );
338        }
339        else if (command == numSideCmd) {
340                numSide = numSideCmd->GetNewIntValue( newValues );
341        }
342        else if (command == pauseCmd) {
343                PauseInput();
344        }
345}
346
347//
348// GetCurrentValue
349//
350G4String FredMessenger::GetCurrentValue( G4UIcommand *command )
351{
352        if (command == volumeTypeNameCmd) {
353                return volumeNames[testVolumeType];
354        }
355        else if (command == gunTypeNameCmd) {
356                return gunNames[gunType];
357        }
358        else if (command == drawTypeNameCmd) {
359                return drawNames[drawType];
360        }
361        else if (command == startPhiCmd) {
362                return startPhiCmd->ConvertToString( startPhi );
363        }
364        else if (command == deltaPhiCmd) {
365                return deltaPhiCmd->ConvertToString( deltaPhi );
366        }
367        else if (command == numSideCmd) {
368                return numSideCmd->ConvertToString( numSide );
369        }
370        return "baloney";
371}
Note: See TracBrowser for help on using the repository browser.