Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VInteractorManager.cc
Go to the documentation of this file.
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
31
32#include <algorithm>
33#include <cstdlib>
34#include <cstring>
35
36#define NewString(str) \
37 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
38
39/***************************************************************************/
41 : argc(0),
42 argv(nullptr),
43 mainInteractor(nullptr),
44 secondaryLoopEnabled(true),
45 alreadyInSecondaryLoop(false),
46 exitSecondaryLoop(0),
47 parentInteractor(nullptr),
48 createdInteractor(nullptr),
49 creationString(nullptr)
50/***************************************************************************/
51/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
52{}
53/***************************************************************************/
55/***************************************************************************/
56/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
57{
58 if (argv != nullptr) {
59 for (G4int argi = 0; argi < argc; ++argi) {
60 if (argv[argi] != nullptr) free(argv[argi]);
61 }
62 free(argv);
63 }
64 argv = nullptr;
65 argc = 0;
66 dispatchers.clear();
67 preActions.clear();
68 postActions.clear();
69 shells.clear();
70 secondaryLoopEnabled = true;
71 alreadyInSecondaryLoop = false;
72 exitSecondaryLoop = 0;
73}
74/***************************************************************************/
75void G4VInteractorManager::SetArguments(G4int a_argc, char** a_argv)
76/***************************************************************************/
77/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
78{
79 // Free previous values.
80 if (argv != nullptr) {
81 for (G4int argi = 0; argi < argc; ++argi) {
82 if (argv[argi] != nullptr) free(argv[argi]);
83 }
84 free(argv);
85 }
86 argv = nullptr;
87 argc = 0;
88 // Set new values.
89 if (a_argc != 0) {
90 argv = (char**)malloc(a_argc * sizeof(char*));
91 if (argv != nullptr) {
92 argc = a_argc;
93 for (G4int argi = 0; argi < a_argc; ++argi) {
94 argv[argi] = (char*)NewString(a_argv[argi]);
95 }
96 }
97 }
98}
99/***************************************************************************/
101/***************************************************************************/
102/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
103{
104 if (a_argc != nullptr) *a_argc = argc;
105 return argv;
106}
107/***************************************************************************/
109/***************************************************************************/
110/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
111{
112 mainInteractor = a_main;
113}
114/***************************************************************************/
116/***************************************************************************/
117/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
118{
119 return mainInteractor;
120}
121/***************************************************************************/
123/***************************************************************************/
124/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
125{
126 secondaryLoopEnabled = true;
127}
128/***************************************************************************/
130/***************************************************************************/
131/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
132{
133 secondaryLoopEnabled = false;
134}
135/***************************************************************************/
137/***************************************************************************/
138/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
139{
140 if (a_dispatcher == nullptr) return;
141 if (std::find(dispatchers.cbegin(), dispatchers.cend(), a_dispatcher) != dispatchers.cend())
142 return;
143 dispatchers.push_back(a_dispatcher);
144}
145/***************************************************************************/
147/***************************************************************************/
148/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
149{
150 std::vector<G4DispatchFunction>::iterator it;
151 for (it = dispatchers.begin(); it != dispatchers.end(); ++it) {
152 if (*it == a_dispatcher) {
153 dispatchers.erase(it);
154 break;
155 }
156 }
157}
158/***************************************************************************/
160/***************************************************************************/
161/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
162{
163 std::size_t dispatchern = dispatchers.size();
165 for (std::size_t count = 0; count < dispatchern; ++count) {
166 func = dispatchers[count];
167 if (func != nullptr) {
168 if (func(a_event)) return;
169 }
170 }
171}
172/***************************************************************************/
174/***************************************************************************/
175/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
176{
177 if (a_preAction == nullptr) return;
178 if (std::find(preActions.cbegin(), preActions.cend(), a_preAction) != preActions.cend()) return;
179 preActions.push_back(a_preAction);
180}
181/***************************************************************************/
183/***************************************************************************/
184/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
185{
186 std::size_t preActionn = preActions.size();
187 for (std::size_t count = 0; count < preActionn; ++count) {
188 if (preActions[count] != nullptr) preActions[count]();
189 }
190}
191/***************************************************************************/
193/***************************************************************************/
194/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
195{
196 if (a_postAction == nullptr) return;
197 if (std::find(postActions.cbegin(), postActions.cend(), a_postAction) != postActions.cend())
198 return;
199 postActions.push_back(a_postAction);
200}
201/***************************************************************************/
203/***************************************************************************/
204/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
205{
206 std::size_t postActionn = postActions.size();
207 for (std::size_t count = 0; count < postActionn; ++count) {
208 if (postActions[count] != nullptr) postActions[count]();
209 }
210}
211/***************************************************************************/
213/***************************************************************************/
214/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
215{
216 if (! Inited()) return;
217
218 if (! secondaryLoopEnabled) return;
219
220 if (! alreadyInSecondaryLoop) {
221 G4cout << "------------------------------------------" << G4endl;
222 G4cout << "You have entered a viewer secondary X event loop." << G4endl;
223 G4cout << "Quit it with an 'Escape' viewer button" << G4endl;
224 alreadyInSecondaryLoop = true;
225 exitSecondaryLoop = 0;
227 // for(G4int count=0;count<shelln;count++) XWidgetUniconify(shells[count]);
228 void* event;
229 while (true) {
230 event = GetEvent();
231 if (event == nullptr) break;
232 DispatchEvent(event);
233 if (exitSecondaryLoop != 0) break;
234 }
235 G4cout << "Secondary X event loop exited." << G4endl;
237 }
238}
239/***************************************************************************/
241/***************************************************************************/
242/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
243{
244 if (! secondaryLoopEnabled) return;
245 if (a_code == 0) a_code = 1;
246 exitSecondaryLoop = a_code;
247 alreadyInSecondaryLoop = false;
248}
249/***************************************************************************/
251/***************************************************************************/
252/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
253{
254 return exitSecondaryLoop;
255}
256/***************************************************************************/
258/***************************************************************************/
259/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
260{
261 if (a_shell == nullptr) return;
262 if (std::find(shells.cbegin(), shells.cend(), a_shell) != shells.cend()) return;
263 shells.push_back(a_shell);
264}
265/***************************************************************************/
267/***************************************************************************/
268/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
269{
270 std::vector<G4Interactor>::iterator it;
271 for (it = shells.begin(); it != shells.end(); ++it) {
272 if (*it == a_shell) {
273 shells.erase(it);
274 break;
275 }
276 }
277}
278/***************************************************************************/
280/***************************************************************************/
281/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
282{
283 parentInteractor = a_interactor;
284}
285/***************************************************************************/
287/***************************************************************************/
288/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
289{
290 return parentInteractor;
291}
292/***************************************************************************/
294/***************************************************************************/
295/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
296{
297 createdInteractor = a_interactor;
298}
299/***************************************************************************/
301/***************************************************************************/
302/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
303{
304 return createdInteractor;
305}
306/***************************************************************************/
308/***************************************************************************/
309/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
310{
311 creationString = a_string;
312}
313/***************************************************************************/
315/***************************************************************************/
316/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
317{
318 return creationString;
319}
int G4int
Definition G4Types.hh:85
#define NewString(str)
G4bool(*)(void *) G4DispatchFunction
void * G4Interactor
void(*)() G4SecondaryLoopAction
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void AddDispatcher(G4DispatchFunction)
void SetCreatedInteractor(G4Interactor)
void SetMainInteractor(G4Interactor)
void AddSecondaryLoopPostAction(G4SecondaryLoopAction)
void SetParentInteractor(G4Interactor)
G4Interactor GetCreatedInteractor()
virtual void * GetEvent()=0
void RemoveShell(G4Interactor)
void RemoveDispatcher(G4DispatchFunction)
virtual G4bool Inited()=0
void AddSecondaryLoopPreAction(G4SecondaryLoopAction)
void SetArguments(int, char **)
void AddShell(G4Interactor)