source: trunk/source/interfaces/common/src/G4VInteractorManager.cc@ 1150

Last change on this file since 1150 was 1139, checked in by garnier, 16 years ago

en test

File size: 13.6 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// $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/***************************************************************************/
43G4VInteractorManager::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/***************************************************************************/
59G4VInteractorManager::~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/***************************************************************************/
81void 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/***************************************************************************/
109char** G4VInteractorManager::GetArguments (
110 G4int* a_argc
111)
112/***************************************************************************/
113/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
114{
115 if(a_argc!=NULL) *a_argc = argc;
116 return argv;
117}
118/***************************************************************************/
119void G4VInteractorManager::SetMainInteractor (
120 G4Interactor a_main
121)
122/***************************************************************************/
123/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
124{
125#ifdef G4DEBUG_INTERFACES_COMMON
126 printf("G4VInteractorManager::SetMainInteractor new ! %d\n",a_main);
127#endif
128 mainInteractor = a_main;
129}
130/***************************************************************************/
131G4Interactor G4VInteractorManager::GetMainInteractor (
132)
133/***************************************************************************/
134/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
135{
136 return mainInteractor;
137}
138/***************************************************************************/
139void G4VInteractorManager::EnableSecondaryLoop (
140)
141/***************************************************************************/
142/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
143{
144 secondaryLoopEnabled = TRUE;
145}
146/***************************************************************************/
147void G4VInteractorManager::DisableSecondaryLoop (
148)
149/***************************************************************************/
150/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
151{
152 secondaryLoopEnabled = FALSE;
153}
154/***************************************************************************/
155void G4VInteractorManager::AddDispatcher (
156 G4DispatchFunction a_dispatcher
157)
158/***************************************************************************/
159/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
160{
161 if(a_dispatcher==NULL) return;
162 if(std::find(dispatchers.begin(),dispatchers.end(),a_dispatcher)!=dispatchers.end()) return;
163 dispatchers.push_back(a_dispatcher);
164}
165/***************************************************************************/
166void G4VInteractorManager::RemoveDispatcher (
167 G4DispatchFunction a_dispatcher
168)
169/***************************************************************************/
170/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
171{
172 std::vector<G4DispatchFunction>::iterator it;
173 for (it = dispatchers.begin(); it != dispatchers.end(); it++) {
174 if (*it == a_dispatcher) {
175 dispatchers.erase(it);
176 break;
177 }
178 }
179}
180/***************************************************************************/
181void G4VInteractorManager::DispatchEvent (
182 void* a_event
183)
184/***************************************************************************/
185/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
186{
187 G4int dispatchern = dispatchers.size();
188 G4DispatchFunction func;
189 for(G4int count=0;count<dispatchern;count++) {
190 func = dispatchers[count];
191 if(func!=NULL) {
192 if(func(a_event)==true) return;
193 }
194 }
195}
196/***************************************************************************/
197void G4VInteractorManager::AddSecondaryLoopPreAction (
198 G4SecondaryLoopAction a_preAction
199)
200/***************************************************************************/
201/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
202{
203 if(a_preAction==NULL) return;
204 if(std::find(preActions.begin(),preActions.end(),a_preAction)!=preActions.end()) return;
205 preActions.push_back(a_preAction);
206}
207/***************************************************************************/
208void G4VInteractorManager::SecondaryLoopPreActions (
209)
210/***************************************************************************/
211/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
212{
213 G4int preActionn = preActions.size();
214 for(G4int count=0;count<preActionn;count++) {
215 if(preActions[count]!=NULL) preActions[count]();
216 }
217}
218/***************************************************************************/
219void G4VInteractorManager::AddSecondaryLoopPostAction (
220 G4SecondaryLoopAction a_postAction
221)
222/***************************************************************************/
223/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
224{
225 if(a_postAction==NULL) return;
226 if(std::find(postActions.begin(),postActions.end(),a_postAction)!=postActions.end()) return;
227 postActions.push_back(a_postAction);
228}
229/***************************************************************************/
230void G4VInteractorManager::SecondaryLoopPostActions (
231)
232/***************************************************************************/
233/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
234{
235 G4int postActionn = postActions.size();
236 for(G4int count=0;count<postActionn;count++) {
237 if(postActions[count]!=NULL) postActions[count]();
238 }
239}
240/***************************************************************************/
241void G4VInteractorManager::SecondaryLoop (
242)
243/***************************************************************************/
244/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
245{
246 if(Inited()==FALSE) return;
247
248 if(secondaryLoopEnabled==FALSE) return;
249
250 if (alreadyInSecondaryLoop==FALSE) {
251 G4cout << "------------------------------------------" << G4endl;
252 G4cout << "You have entered a viewer secondary X event loop." << G4endl;
253 G4cout << "Quit it with an 'Escape' viewer button" << G4endl;
254 alreadyInSecondaryLoop = TRUE;
255 exitSecondaryLoop = 0;
256 SecondaryLoopPreActions ();
257 //for(G4int count=0;count<shelln;count++) XWidgetUniconify(shells[count]);
258 void* event;
259 while(1) {
260 event = GetEvent();
261 if(event==NULL) break;
262 DispatchEvent (event);
263 if(exitSecondaryLoop!=0) break;
264 }
265 G4cout << "Secondary X event loop exited." << G4endl;
266 SecondaryLoopPostActions ();
267 }
268}
269/***************************************************************************/
270void G4VInteractorManager::RequireExitSecondaryLoop (
271 G4int a_code
272)
273/***************************************************************************/
274/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
275{
276 if(secondaryLoopEnabled==FALSE) return;
277 if(a_code==0) a_code = 1;
278 exitSecondaryLoop = a_code;
279 alreadyInSecondaryLoop = FALSE;
280 // for(G4int count=0;count<shelln;count++) XWidgetIconify(shells[count]);
281 // if(shelln!=0) XSync(XtDisplay(topWidget),False);
282}
283/***************************************************************************/
284G4int G4VInteractorManager::GetExitSecondaryLoopCode (
285)
286/***************************************************************************/
287/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
288{
289 return exitSecondaryLoop;
290}
291/***************************************************************************/
292void G4VInteractorManager::AddShell (
293 G4Interactor a_shell
294)
295/***************************************************************************/
296/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
297{
298 if(a_shell==NULL) return;
299 if(std::find(shells.begin(),shells.end(),a_shell)!=shells.end()) return;
300 shells.push_back(a_shell);
301}
302/***************************************************************************/
303void G4VInteractorManager::RemoveShell (
304 G4Interactor a_shell
305)
306/***************************************************************************/
307/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
308{
309 std::vector<G4Interactor>::iterator it;
310 for (it = shells.begin(); it != shells.end(); it++) {
311 if (*it == a_shell) {
312 shells.erase(it);
313 break;
314 }
315 }
316}
317/***************************************************************************/
318void G4VInteractorManager::SetParentInteractor (
319 G4Interactor a_interactor
320)
321/***************************************************************************/
322/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
323{
324 parentInteractor = a_interactor;
325}
326/***************************************************************************/
327G4Interactor G4VInteractorManager::GetParentInteractor (
328)
329/***************************************************************************/
330/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
331{
332 return parentInteractor;
333}
334/***************************************************************************/
335void G4VInteractorManager::SetCreatedInteractor (
336 G4Interactor a_interactor
337)
338/***************************************************************************/
339/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
340{
341 createdInteractor = a_interactor;
342}
343/***************************************************************************/
344G4Interactor G4VInteractorManager::GetCreatedInteractor (
345)
346/***************************************************************************/
347/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
348{
349 return createdInteractor;
350}
351/***************************************************************************/
352void G4VInteractorManager::SetCreationString (
353 char* a_string
354)
355/***************************************************************************/
356/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
357{
358 creationString = a_string;
359}
360/***************************************************************************/
361char* G4VInteractorManager::GetCreationString (
362)
363/***************************************************************************/
364/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
365{
366 return creationString;
367}
368
Note: See TracBrowser for help on using the repository browser.