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 | // $Id: G4VInteractorManager.cc,v 1.13 2006/06/29 19:10:24 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // G.Barrand |
---|
31 | |
---|
32 | #include <stdlib.h> |
---|
33 | #include <string.h> |
---|
34 | |
---|
35 | #include <algorithm> |
---|
36 | |
---|
37 | #include "G4VInteractorManager.hh" |
---|
38 | |
---|
39 | #define NewString(str) \ |
---|
40 | ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL) |
---|
41 | |
---|
42 | /***************************************************************************/ |
---|
43 | G4VInteractorManager::G4VInteractorManager ( |
---|
44 | ) |
---|
45 | :argc(0) |
---|
46 | ,argv(NULL) |
---|
47 | ,mainInteractor(NULL) |
---|
48 | ,secondaryLoopEnabled(TRUE) |
---|
49 | ,alreadyInSecondaryLoop(FALSE) |
---|
50 | ,exitSecondaryLoop(0) |
---|
51 | ,parentInteractor(NULL) |
---|
52 | ,createdInteractor(NULL) |
---|
53 | ,creationString(NULL) |
---|
54 | /***************************************************************************/ |
---|
55 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
56 | { |
---|
57 | } |
---|
58 | /***************************************************************************/ |
---|
59 | G4VInteractorManager::~G4VInteractorManager ( |
---|
60 | ) |
---|
61 | /***************************************************************************/ |
---|
62 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
63 | { |
---|
64 | if(argv!=NULL) { |
---|
65 | for(G4int argi=0;argi<argc;argi++) { |
---|
66 | if(argv[argi]!=NULL) free(argv[argi]); |
---|
67 | } |
---|
68 | free (argv); |
---|
69 | } |
---|
70 | argv = NULL; |
---|
71 | argc = 0; |
---|
72 | dispatchers.clear(); |
---|
73 | preActions.clear(); |
---|
74 | postActions.clear(); |
---|
75 | shells.clear(); |
---|
76 | secondaryLoopEnabled = TRUE; |
---|
77 | alreadyInSecondaryLoop = FALSE; |
---|
78 | exitSecondaryLoop = 0; |
---|
79 | } |
---|
80 | /***************************************************************************/ |
---|
81 | void G4VInteractorManager::SetArguments ( |
---|
82 | G4int a_argc |
---|
83 | ,char** a_argv |
---|
84 | ) |
---|
85 | /***************************************************************************/ |
---|
86 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
87 | { |
---|
88 | // Free previous values. |
---|
89 | if(argv!=NULL) { |
---|
90 | for(G4int argi=0;argi<argc;argi++) { |
---|
91 | if(argv[argi]!=NULL) free(argv[argi]); |
---|
92 | } |
---|
93 | free(argv); |
---|
94 | } |
---|
95 | argv = NULL; |
---|
96 | argc = 0; |
---|
97 | // Set new values. |
---|
98 | if(a_argc!=0) { |
---|
99 | argv = (char**)malloc(a_argc * sizeof(char*)); |
---|
100 | if(argv!=NULL) { |
---|
101 | argc = a_argc; |
---|
102 | for(G4int argi=0;argi<a_argc;argi++) { |
---|
103 | argv[argi] = (char*)NewString (a_argv[argi]); |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | /***************************************************************************/ |
---|
109 | char** G4VInteractorManager::GetArguments ( |
---|
110 | G4int* a_argc |
---|
111 | ) |
---|
112 | /***************************************************************************/ |
---|
113 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
114 | { |
---|
115 | if(a_argc!=NULL) *a_argc = argc; |
---|
116 | return argv; |
---|
117 | } |
---|
118 | /***************************************************************************/ |
---|
119 | void G4VInteractorManager::SetMainInteractor ( |
---|
120 | G4Interactor a_main |
---|
121 | ) |
---|
122 | /***************************************************************************/ |
---|
123 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
124 | { |
---|
125 | mainInteractor = a_main; |
---|
126 | } |
---|
127 | /***************************************************************************/ |
---|
128 | G4Interactor G4VInteractorManager::GetMainInteractor ( |
---|
129 | ) |
---|
130 | /***************************************************************************/ |
---|
131 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
132 | { |
---|
133 | return mainInteractor; |
---|
134 | } |
---|
135 | /***************************************************************************/ |
---|
136 | void G4VInteractorManager::EnableSecondaryLoop ( |
---|
137 | ) |
---|
138 | /***************************************************************************/ |
---|
139 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
140 | { |
---|
141 | secondaryLoopEnabled = TRUE; |
---|
142 | } |
---|
143 | /***************************************************************************/ |
---|
144 | void G4VInteractorManager::DisableSecondaryLoop ( |
---|
145 | ) |
---|
146 | /***************************************************************************/ |
---|
147 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
148 | { |
---|
149 | secondaryLoopEnabled = FALSE; |
---|
150 | } |
---|
151 | /***************************************************************************/ |
---|
152 | void G4VInteractorManager::AddDispatcher ( |
---|
153 | G4DispatchFunction a_dispatcher |
---|
154 | ) |
---|
155 | /***************************************************************************/ |
---|
156 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
157 | { |
---|
158 | if(a_dispatcher==NULL) return; |
---|
159 | if(std::find(dispatchers.begin(),dispatchers.end(),a_dispatcher)!=dispatchers.end()) return; |
---|
160 | dispatchers.push_back(a_dispatcher); |
---|
161 | } |
---|
162 | /***************************************************************************/ |
---|
163 | void G4VInteractorManager::RemoveDispatcher ( |
---|
164 | G4DispatchFunction a_dispatcher |
---|
165 | ) |
---|
166 | /***************************************************************************/ |
---|
167 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
168 | { |
---|
169 | std::vector<G4DispatchFunction>::iterator it; |
---|
170 | for (it = dispatchers.begin(); it != dispatchers.end(); it++) { |
---|
171 | if (*it == a_dispatcher) { |
---|
172 | dispatchers.erase(it); |
---|
173 | break; |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | /***************************************************************************/ |
---|
178 | void G4VInteractorManager::DispatchEvent ( |
---|
179 | void* a_event |
---|
180 | ) |
---|
181 | /***************************************************************************/ |
---|
182 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
183 | { |
---|
184 | G4int dispatchern = dispatchers.size(); |
---|
185 | G4DispatchFunction func; |
---|
186 | for(G4int count=0;count<dispatchern;count++) { |
---|
187 | func = dispatchers[count]; |
---|
188 | if(func!=NULL) { |
---|
189 | if(func(a_event)==true) return; |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | /***************************************************************************/ |
---|
194 | void G4VInteractorManager::AddSecondaryLoopPreAction ( |
---|
195 | G4SecondaryLoopAction a_preAction |
---|
196 | ) |
---|
197 | /***************************************************************************/ |
---|
198 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
199 | { |
---|
200 | if(a_preAction==NULL) return; |
---|
201 | if(std::find(preActions.begin(),preActions.end(),a_preAction)!=preActions.end()) return; |
---|
202 | preActions.push_back(a_preAction); |
---|
203 | } |
---|
204 | /***************************************************************************/ |
---|
205 | void G4VInteractorManager::SecondaryLoopPreActions ( |
---|
206 | ) |
---|
207 | /***************************************************************************/ |
---|
208 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
209 | { |
---|
210 | G4int preActionn = preActions.size(); |
---|
211 | for(G4int count=0;count<preActionn;count++) { |
---|
212 | if(preActions[count]!=NULL) preActions[count](); |
---|
213 | } |
---|
214 | } |
---|
215 | /***************************************************************************/ |
---|
216 | void G4VInteractorManager::AddSecondaryLoopPostAction ( |
---|
217 | G4SecondaryLoopAction a_postAction |
---|
218 | ) |
---|
219 | /***************************************************************************/ |
---|
220 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
221 | { |
---|
222 | if(a_postAction==NULL) return; |
---|
223 | if(std::find(postActions.begin(),postActions.end(),a_postAction)!=postActions.end()) return; |
---|
224 | postActions.push_back(a_postAction); |
---|
225 | } |
---|
226 | /***************************************************************************/ |
---|
227 | void G4VInteractorManager::SecondaryLoopPostActions ( |
---|
228 | ) |
---|
229 | /***************************************************************************/ |
---|
230 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
231 | { |
---|
232 | G4int postActionn = postActions.size(); |
---|
233 | for(G4int count=0;count<postActionn;count++) { |
---|
234 | if(postActions[count]!=NULL) postActions[count](); |
---|
235 | } |
---|
236 | } |
---|
237 | /***************************************************************************/ |
---|
238 | void G4VInteractorManager::SecondaryLoop ( |
---|
239 | ) |
---|
240 | /***************************************************************************/ |
---|
241 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
242 | { |
---|
243 | if(Inited()==FALSE) return; |
---|
244 | |
---|
245 | if(secondaryLoopEnabled==FALSE) return; |
---|
246 | |
---|
247 | if (alreadyInSecondaryLoop==FALSE) { |
---|
248 | G4cout << "------------------------------------------" << G4endl; |
---|
249 | G4cout << "You have entered a viewer secondary X event loop." << G4endl; |
---|
250 | G4cout << "Quit it with an 'Escape' viewer button" << G4endl; |
---|
251 | alreadyInSecondaryLoop = TRUE; |
---|
252 | exitSecondaryLoop = 0; |
---|
253 | SecondaryLoopPreActions (); |
---|
254 | //for(G4int count=0;count<shelln;count++) XWidgetUniconify(shells[count]); |
---|
255 | void* event; |
---|
256 | while(1) { |
---|
257 | event = GetEvent(); |
---|
258 | if(event==NULL) break; |
---|
259 | DispatchEvent (event); |
---|
260 | if(exitSecondaryLoop!=0) break; |
---|
261 | } |
---|
262 | G4cout << "Secondary X event loop exited." << G4endl; |
---|
263 | SecondaryLoopPostActions (); |
---|
264 | } |
---|
265 | } |
---|
266 | /***************************************************************************/ |
---|
267 | void G4VInteractorManager::RequireExitSecondaryLoop ( |
---|
268 | G4int a_code |
---|
269 | ) |
---|
270 | /***************************************************************************/ |
---|
271 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
272 | { |
---|
273 | if(secondaryLoopEnabled==FALSE) return; |
---|
274 | if(a_code==0) a_code = 1; |
---|
275 | exitSecondaryLoop = a_code; |
---|
276 | alreadyInSecondaryLoop = FALSE; |
---|
277 | // for(G4int count=0;count<shelln;count++) XWidgetIconify(shells[count]); |
---|
278 | // if(shelln!=0) XSync(XtDisplay(topWidget),False); |
---|
279 | } |
---|
280 | /***************************************************************************/ |
---|
281 | G4int G4VInteractorManager::GetExitSecondaryLoopCode ( |
---|
282 | ) |
---|
283 | /***************************************************************************/ |
---|
284 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
285 | { |
---|
286 | return exitSecondaryLoop; |
---|
287 | } |
---|
288 | /***************************************************************************/ |
---|
289 | void G4VInteractorManager::AddShell ( |
---|
290 | G4Interactor a_shell |
---|
291 | ) |
---|
292 | /***************************************************************************/ |
---|
293 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
294 | { |
---|
295 | if(a_shell==NULL) return; |
---|
296 | if(std::find(shells.begin(),shells.end(),a_shell)!=shells.end()) return; |
---|
297 | shells.push_back(a_shell); |
---|
298 | } |
---|
299 | /***************************************************************************/ |
---|
300 | void G4VInteractorManager::RemoveShell ( |
---|
301 | G4Interactor a_shell |
---|
302 | ) |
---|
303 | /***************************************************************************/ |
---|
304 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
305 | { |
---|
306 | std::vector<G4Interactor>::iterator it; |
---|
307 | for (it = shells.begin(); it != shells.end(); it++) { |
---|
308 | if (*it == a_shell) { |
---|
309 | shells.erase(it); |
---|
310 | break; |
---|
311 | } |
---|
312 | } |
---|
313 | } |
---|
314 | /***************************************************************************/ |
---|
315 | void G4VInteractorManager::SetParentInteractor ( |
---|
316 | G4Interactor a_interactor |
---|
317 | ) |
---|
318 | /***************************************************************************/ |
---|
319 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
320 | { |
---|
321 | parentInteractor = a_interactor; |
---|
322 | } |
---|
323 | /***************************************************************************/ |
---|
324 | G4Interactor G4VInteractorManager::GetParentInteractor ( |
---|
325 | ) |
---|
326 | /***************************************************************************/ |
---|
327 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
328 | { |
---|
329 | return parentInteractor; |
---|
330 | } |
---|
331 | /***************************************************************************/ |
---|
332 | void G4VInteractorManager::SetCreatedInteractor ( |
---|
333 | G4Interactor a_interactor |
---|
334 | ) |
---|
335 | /***************************************************************************/ |
---|
336 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
337 | { |
---|
338 | createdInteractor = a_interactor; |
---|
339 | } |
---|
340 | /***************************************************************************/ |
---|
341 | G4Interactor G4VInteractorManager::GetCreatedInteractor ( |
---|
342 | ) |
---|
343 | /***************************************************************************/ |
---|
344 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
345 | { |
---|
346 | return createdInteractor; |
---|
347 | } |
---|
348 | /***************************************************************************/ |
---|
349 | void G4VInteractorManager::SetCreationString ( |
---|
350 | char* a_string |
---|
351 | ) |
---|
352 | /***************************************************************************/ |
---|
353 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
354 | { |
---|
355 | creationString = a_string; |
---|
356 | } |
---|
357 | /***************************************************************************/ |
---|
358 | char* G4VInteractorManager::GetCreationString ( |
---|
359 | ) |
---|
360 | /***************************************************************************/ |
---|
361 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
362 | { |
---|
363 | return creationString; |
---|
364 | } |
---|
365 | |
---|