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 | // FredVoxelTestMessenger.cc |
---|
28 | // |
---|
29 | |
---|
30 | #include "FredVoxelTestMessenger.hh" |
---|
31 | #include "FredVoxelTest.hh" |
---|
32 | |
---|
33 | #include "G4UIdirectory.hh" |
---|
34 | #include "G4UIcommand.hh" |
---|
35 | #include "G4UIcmdWithoutParameter.hh" |
---|
36 | #include "G4UIcmdWith3VectorAndUnit.hh" |
---|
37 | #include "G4UIcmdWithAString.hh" |
---|
38 | #include "G4UIcmdWithADouble.hh" |
---|
39 | |
---|
40 | #include "G4VVisManager.hh" |
---|
41 | #include "G4UImanager.hh" |
---|
42 | |
---|
43 | // |
---|
44 | // Constructor |
---|
45 | // |
---|
46 | FredVoxelTestMessenger::FredVoxelTestMessenger() |
---|
47 | { |
---|
48 | voxelTest = new FredVoxelTest(); |
---|
49 | |
---|
50 | // |
---|
51 | // Declare directory |
---|
52 | // |
---|
53 | voxelTestDirectory = new G4UIdirectory( "/fred/voxel/" ); |
---|
54 | voxelTestDirectory->SetGuidance( "Controls for voxel test" ); |
---|
55 | |
---|
56 | // |
---|
57 | // X min/max command |
---|
58 | // |
---|
59 | xMinMaxCmd = new G4UIcmdWith3VectorAndUnit( "/fred/voxel/xextent", this ); |
---|
60 | xMinMaxCmd->SetGuidance( "Max/min value along voxel x axis" ); |
---|
61 | xMinMaxCmd->SetParameterName( "Min", "Max", "NotUsed", true, true ); |
---|
62 | |
---|
63 | // |
---|
64 | // Y min/max command |
---|
65 | // |
---|
66 | yMinMaxCmd = new G4UIcmdWith3VectorAndUnit( "/fred/voxel/yextent", this ); |
---|
67 | yMinMaxCmd->SetGuidance( "Max/min value along voxel y axis" ); |
---|
68 | yMinMaxCmd->SetParameterName( "Min", "Max", "NotUsed", true, true ); |
---|
69 | |
---|
70 | // |
---|
71 | // Z min/max command |
---|
72 | // |
---|
73 | zMinMaxCmd = new G4UIcmdWith3VectorAndUnit( "/fred/voxel/zextent", this ); |
---|
74 | zMinMaxCmd->SetGuidance( "Max/min value along voxel z axis" ); |
---|
75 | zMinMaxCmd->SetParameterName( "Min", "Max", "NotUsed", true, true ); |
---|
76 | |
---|
77 | // |
---|
78 | // Position command |
---|
79 | // |
---|
80 | posCmd = new G4UIcmdWith3VectorAndUnit( "/fred/voxel/position", this ); |
---|
81 | posCmd->SetGuidance( "Position of voxel" ); |
---|
82 | posCmd->SetParameterName( "X", "Y", "Z", true, true ); |
---|
83 | |
---|
84 | // |
---|
85 | // Rotate commands |
---|
86 | // |
---|
87 | xRotateCmd = new G4UIcmdWithADouble( "/fred/voxel/xrotate", this ); |
---|
88 | xRotateCmd->SetGuidance( "Rotate around x axis" ); |
---|
89 | |
---|
90 | yRotateCmd = new G4UIcmdWithADouble( "/fred/voxel/yrotate", this ); |
---|
91 | yRotateCmd->SetGuidance( "Rotate around y axis" ); |
---|
92 | |
---|
93 | zRotateCmd = new G4UIcmdWithADouble( "/fred/voxel/zrotate", this ); |
---|
94 | zRotateCmd->SetGuidance( "Rotate around z axis" ); |
---|
95 | |
---|
96 | levelCmd = new G4UIcmdWithoutParameter( "/fred/voxel/level", this ); |
---|
97 | levelCmd->SetGuidance( "Reset rotation" ); |
---|
98 | |
---|
99 | // |
---|
100 | // Draw command |
---|
101 | // |
---|
102 | drawCmd = new G4UIcmdWithAString( "/fred/voxel/draw", this ); |
---|
103 | drawCmd->SetGuidance( "Test and draw the voxel" ); |
---|
104 | drawCmd->SetCandidates( "x y z" ); |
---|
105 | |
---|
106 | // |
---|
107 | // Test command |
---|
108 | // |
---|
109 | testCmd = new G4UIcmdWithAString( "/fred/voxel/test", this ); |
---|
110 | testCmd->SetGuidance( "Apply the voxel to the test volume" ); |
---|
111 | testCmd->SetCandidates( "x y z" ); |
---|
112 | |
---|
113 | // |
---|
114 | // Reset command |
---|
115 | // |
---|
116 | resetCmd = new G4UIcmdWithoutParameter( "/fred/voxel/reset", this ); |
---|
117 | resetCmd->SetGuidance( "Start with a fresh voxel" ); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | // |
---|
122 | // Destructor |
---|
123 | // |
---|
124 | FredVoxelTestMessenger::~FredVoxelTestMessenger() |
---|
125 | { |
---|
126 | delete xMinMaxCmd; |
---|
127 | delete yMinMaxCmd; |
---|
128 | delete zMinMaxCmd; |
---|
129 | delete posCmd; |
---|
130 | delete drawCmd; |
---|
131 | delete testCmd; |
---|
132 | delete voxelTestDirectory; |
---|
133 | |
---|
134 | delete voxelTest; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | // |
---|
139 | // InvokeTest |
---|
140 | // |
---|
141 | void FredVoxelTestMessenger::InvokeTest( G4String request ) |
---|
142 | { |
---|
143 | if (testVolume== 0) { |
---|
144 | G4cerr << "Please initialize geometry before running test 3" << G4endl; |
---|
145 | G4cerr << "Test 3 ABORTED" << G4endl; |
---|
146 | return; |
---|
147 | } |
---|
148 | |
---|
149 | EAxis axis; |
---|
150 | |
---|
151 | if ( request == "x" ) |
---|
152 | axis = kXAxis; |
---|
153 | else if ( request == "y" ) |
---|
154 | axis = kYAxis; |
---|
155 | else if ( request == "z" ) |
---|
156 | axis = kZAxis; |
---|
157 | else { |
---|
158 | G4cerr << "Please specify x, y, or z" << G4endl; |
---|
159 | return; |
---|
160 | } |
---|
161 | |
---|
162 | voxelTest->Test( axis, testVolume ); |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | // |
---|
167 | // Draw |
---|
168 | // |
---|
169 | void FredVoxelTestMessenger::Draw() |
---|
170 | { |
---|
171 | if (G4VVisManager::GetConcreteInstance()) { |
---|
172 | G4UImanager *UI = G4UImanager::GetUIpointer(); |
---|
173 | |
---|
174 | // Prepare |
---|
175 | UI->ApplyCommand( "/vis~/clear/view" ); |
---|
176 | |
---|
177 | // Draw detector |
---|
178 | UI->ApplyCommand( "/vis~/draw/current" ); |
---|
179 | |
---|
180 | // Draw voxel |
---|
181 | voxelTest->Draw(); |
---|
182 | |
---|
183 | // Finish |
---|
184 | UI->ApplyCommand( "/vis~/show/view" ); |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | // |
---|
190 | // SetNewVaolume |
---|
191 | // |
---|
192 | // Call by the UI when user requests a change |
---|
193 | // |
---|
194 | void FredVoxelTestMessenger::SetNewValue( G4UIcommand *command, G4String newValues ) |
---|
195 | { |
---|
196 | if (command == xMinMaxCmd) { |
---|
197 | G4ThreeVector param = xMinMaxCmd->GetNew3VectorValue( newValues ); |
---|
198 | voxelTest->SetExtent( kXAxis, param.x(), param.y() ); |
---|
199 | } |
---|
200 | else if (command == yMinMaxCmd) { |
---|
201 | G4ThreeVector param = yMinMaxCmd->GetNew3VectorValue( newValues ); |
---|
202 | voxelTest->SetExtent( kYAxis, param.x(), param.y() ); |
---|
203 | } |
---|
204 | else if (command == zMinMaxCmd) { |
---|
205 | G4ThreeVector param = zMinMaxCmd->GetNew3VectorValue( newValues ); |
---|
206 | voxelTest->SetExtent( kZAxis, param.x(), param.y() ); |
---|
207 | } |
---|
208 | else if (command == posCmd) { |
---|
209 | voxelTest->SetOrigin( posCmd->GetNew3VectorValue( newValues ) ); |
---|
210 | } |
---|
211 | else if (command == xRotateCmd) { |
---|
212 | voxelTest->Rotate( kXAxis, deg*xRotateCmd->GetNewDoubleValue( newValues ) ); |
---|
213 | } |
---|
214 | else if (command == yRotateCmd) { |
---|
215 | voxelTest->Rotate( kYAxis, deg*yRotateCmd->GetNewDoubleValue( newValues ) ); |
---|
216 | } |
---|
217 | else if (command == zRotateCmd) { |
---|
218 | voxelTest->Rotate( kZAxis, deg*zRotateCmd->GetNewDoubleValue( newValues ) ); |
---|
219 | } |
---|
220 | else if (command == levelCmd) { |
---|
221 | voxelTest->ResetRotation(); |
---|
222 | } |
---|
223 | else if (command == drawCmd) { |
---|
224 | InvokeTest( newValues ); |
---|
225 | Draw(); |
---|
226 | } |
---|
227 | else if (command == testCmd) { |
---|
228 | InvokeTest( newValues ); |
---|
229 | } |
---|
230 | else if (command == resetCmd) { |
---|
231 | delete voxelTest; |
---|
232 | voxelTest = new FredVoxelTest(); |
---|
233 | } |
---|
234 | else { |
---|
235 | G4Exception( "Unrecognized command" ); |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | |
---|
241 | |
---|
242 | |
---|
243 | // |
---|
244 | // GetCurrentValue |
---|
245 | // |
---|
246 | G4String FredVoxelTestMessenger::GetCurrentValue( G4UIcommand * ) |
---|
247 | { |
---|
248 | return "fred"; |
---|
249 | } |
---|
250 | |
---|