ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VInteractorManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VInteractorManager.cc
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 //
28 // G.Barrand
29 
30 #include <stdlib.h>
31 #include <string.h>
32 
33 #include <algorithm>
34 
35 #include "G4VInteractorManager.hh"
36 
37 #define NewString(str) \
38  ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
39 
40 /***************************************************************************/
42 )
43 :argc(0)
44 ,argv(NULL)
45 ,mainInteractor(NULL)
46 ,secondaryLoopEnabled(TRUE)
47 ,alreadyInSecondaryLoop(FALSE)
48 ,exitSecondaryLoop(0)
49 ,parentInteractor(NULL)
50 ,createdInteractor(NULL)
51 ,creationString(NULL)
52 /***************************************************************************/
54 {
55 }
56 /***************************************************************************/
58 )
59 /***************************************************************************/
61 {
62  if(argv!=NULL) {
63  for(G4int argi=0;argi<argc;argi++) {
64  if(argv[argi]!=NULL) free(argv[argi]);
65  }
66  free (argv);
67  }
68  argv = NULL;
69  argc = 0;
70  dispatchers.clear();
71  preActions.clear();
72  postActions.clear();
73  shells.clear();
77 }
78 /***************************************************************************/
80  G4int a_argc
81 ,char** a_argv
82 )
83 /***************************************************************************/
85 {
86  // Free previous values.
87  if(argv!=NULL) {
88  for(G4int argi=0;argi<argc;argi++) {
89  if(argv[argi]!=NULL) free(argv[argi]);
90  }
91  free(argv);
92  }
93  argv = NULL;
94  argc = 0;
95  // Set new values.
96  if(a_argc!=0) {
97  argv = (char**)malloc(a_argc * sizeof(char*));
98  if(argv!=NULL) {
99  argc = a_argc;
100  for(G4int argi=0;argi<a_argc;argi++) {
101  argv[argi] = (char*)NewString (a_argv[argi]);
102  }
103  }
104  }
105 }
106 /***************************************************************************/
108  G4int* a_argc
109 )
110 /***************************************************************************/
112 {
113  if(a_argc!=NULL) *a_argc = argc;
114  return argv;
115 }
116 /***************************************************************************/
118  G4Interactor a_main
119 )
120 /***************************************************************************/
122 {
123  mainInteractor = a_main;
124 }
125 /***************************************************************************/
127 )
128 /***************************************************************************/
130 {
131  return mainInteractor;
132 }
133 /***************************************************************************/
135 )
136 /***************************************************************************/
138 {
140 }
141 /***************************************************************************/
143 )
144 /***************************************************************************/
146 {
148 }
149 /***************************************************************************/
151  G4DispatchFunction a_dispatcher
152 )
153 /***************************************************************************/
155 {
156  if(a_dispatcher==NULL) return;
157  if(std::find(dispatchers.begin(),dispatchers.end(),a_dispatcher)!=dispatchers.end()) return;
158  dispatchers.push_back(a_dispatcher);
159 }
160 /***************************************************************************/
162  G4DispatchFunction a_dispatcher
163 )
164 /***************************************************************************/
166 {
167  std::vector<G4DispatchFunction>::iterator it;
168  for (it = dispatchers.begin(); it != dispatchers.end(); it++) {
169  if (*it == a_dispatcher) {
170  dispatchers.erase(it);
171  break;
172  }
173  }
174 }
175 /***************************************************************************/
177  void* a_event
178 )
179 /***************************************************************************/
181 {
182  G4int dispatchern = dispatchers.size();
184  for(G4int count=0;count<dispatchern;count++) {
185  func = dispatchers[count];
186  if(func!=NULL) {
187  if(func(a_event)==true) return;
188  }
189  }
190 }
191 /***************************************************************************/
193  G4SecondaryLoopAction a_preAction
194 )
195 /***************************************************************************/
197 {
198  if(a_preAction==NULL) return;
199  if(std::find(preActions.begin(),preActions.end(),a_preAction)!=preActions.end()) return;
200  preActions.push_back(a_preAction);
201 }
202 /***************************************************************************/
204 )
205 /***************************************************************************/
207 {
208  G4int preActionn = preActions.size();
209  for(G4int count=0;count<preActionn;count++) {
210  if(preActions[count]!=NULL) preActions[count]();
211  }
212 }
213 /***************************************************************************/
215  G4SecondaryLoopAction a_postAction
216 )
217 /***************************************************************************/
219 {
220  if(a_postAction==NULL) return;
221  if(std::find(postActions.begin(),postActions.end(),a_postAction)!=postActions.end()) return;
222  postActions.push_back(a_postAction);
223 }
224 /***************************************************************************/
226 )
227 /***************************************************************************/
229 {
230  G4int postActionn = postActions.size();
231  for(G4int count=0;count<postActionn;count++) {
232  if(postActions[count]!=NULL) postActions[count]();
233  }
234 }
235 /***************************************************************************/
237 )
238 /***************************************************************************/
240 {
241  if(Inited()==FALSE) return;
242 
243  if(secondaryLoopEnabled==FALSE) return;
244 
246  G4cout << "------------------------------------------" << G4endl;
247  G4cout << "You have entered a viewer secondary X event loop." << G4endl;
248  G4cout << "Quit it with an 'Escape' viewer button" << G4endl;
250  exitSecondaryLoop = 0;
252  //for(G4int count=0;count<shelln;count++) XWidgetUniconify(shells[count]);
253  void* event;
254  while(1) {
255  event = GetEvent();
256  if(event==NULL) break;
257  DispatchEvent (event);
258  if(exitSecondaryLoop!=0) break;
259  }
260  G4cout << "Secondary X event loop exited." << G4endl;
262  }
263 }
264 /***************************************************************************/
266  G4int a_code
267 )
268 /***************************************************************************/
270 {
271  if(secondaryLoopEnabled==FALSE) return;
272  if(a_code==0) a_code = 1;
273  exitSecondaryLoop = a_code;
275  // for(G4int count=0;count<shelln;count++) XWidgetIconify(shells[count]);
276  // if(shelln!=0) XSync(XtDisplay(topWidget),False);
277 }
278 /***************************************************************************/
280 )
281 /***************************************************************************/
283 {
284  return exitSecondaryLoop;
285 }
286 /***************************************************************************/
288  G4Interactor a_shell
289 )
290 /***************************************************************************/
292 {
293  if(a_shell==NULL) return;
294  if(std::find(shells.begin(),shells.end(),a_shell)!=shells.end()) return;
295  shells.push_back(a_shell);
296 }
297 /***************************************************************************/
299  G4Interactor a_shell
300 )
301 /***************************************************************************/
303 {
304  std::vector<G4Interactor>::iterator it;
305  for (it = shells.begin(); it != shells.end(); it++) {
306  if (*it == a_shell) {
307  shells.erase(it);
308  break;
309  }
310  }
311 }
312 /***************************************************************************/
314  G4Interactor a_interactor
315 )
316 /***************************************************************************/
318 {
319  parentInteractor = a_interactor;
320 }
321 /***************************************************************************/
323 )
324 /***************************************************************************/
326 {
327  return parentInteractor;
328 }
329 /***************************************************************************/
331  G4Interactor a_interactor
332 )
333 /***************************************************************************/
335 {
336  createdInteractor = a_interactor;
337 }
338 /***************************************************************************/
340 )
341 /***************************************************************************/
343 {
344  return createdInteractor;
345 }
346 /***************************************************************************/
348  char* a_string
349 )
350 /***************************************************************************/
352 {
353  creationString = a_string;
354 }
355 /***************************************************************************/
357 )
358 /***************************************************************************/
360 {
361  return creationString;
362 }
363