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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 "G4VInteractorManager.hh"
 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 /***************************************************************************/
 40 G4VInteractorManager::G4VInteractorManager()
 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 /***************************************************************************/
 54 G4VInteractorManager::~G4VInteractorManager()
 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 /***************************************************************************/
 75 void 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 /***************************************************************************/
100 char** G4VInteractorManager::GetArguments(G4int* a_argc)
101 /***************************************************************************/
102 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
103 {
104   if (a_argc != nullptr) *a_argc = argc;
105   return argv;
106 }
107 /***************************************************************************/
108 void G4VInteractorManager::SetMainInteractor(G4Interactor a_main)
109 /***************************************************************************/
110 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
111 {
112   mainInteractor = a_main;
113 }
114 /***************************************************************************/
115 G4Interactor G4VInteractorManager::GetMainInteractor()
116 /***************************************************************************/
117 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
118 {
119   return mainInteractor;
120 }
121 /***************************************************************************/
122 void G4VInteractorManager::EnableSecondaryLoop()
123 /***************************************************************************/
124 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
125 {
126   secondaryLoopEnabled = true;
127 }
128 /***************************************************************************/
129 void G4VInteractorManager::DisableSecondaryLoop()
130 /***************************************************************************/
131 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
132 {
133   secondaryLoopEnabled = false;
134 }
135 /***************************************************************************/
136 void G4VInteractorManager::AddDispatcher(G4DispatchFunction a_dispatcher)
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 /***************************************************************************/
146 void G4VInteractorManager::RemoveDispatcher(G4DispatchFunction a_dispatcher)
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 /***************************************************************************/
159 void G4VInteractorManager::DispatchEvent(void* a_event)
160 /***************************************************************************/
161 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
162 {
163   std::size_t dispatchern = dispatchers.size();
164   G4DispatchFunction func;
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 /***************************************************************************/
173 void G4VInteractorManager::AddSecondaryLoopPreAction(G4SecondaryLoopAction a_preAction)
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 /***************************************************************************/
182 void G4VInteractorManager::SecondaryLoopPreActions()
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 /***************************************************************************/
192 void G4VInteractorManager::AddSecondaryLoopPostAction(G4SecondaryLoopAction a_postAction)
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 /***************************************************************************/
202 void G4VInteractorManager::SecondaryLoopPostActions()
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 /***************************************************************************/
212 void G4VInteractorManager::SecondaryLoop()
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;
226     SecondaryLoopPreActions();
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;
236     SecondaryLoopPostActions();
237   }
238 }
239 /***************************************************************************/
240 void G4VInteractorManager::RequireExitSecondaryLoop(G4int a_code)
241 /***************************************************************************/
242 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
243 {
244   if (! secondaryLoopEnabled) return;
245   if (a_code == 0) a_code = 1;
246   exitSecondaryLoop = a_code;
247   alreadyInSecondaryLoop = false;
248 }
249 /***************************************************************************/
250 G4int G4VInteractorManager::GetExitSecondaryLoopCode()
251 /***************************************************************************/
252 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
253 {
254   return exitSecondaryLoop;
255 }
256 /***************************************************************************/
257 void G4VInteractorManager::AddShell(G4Interactor a_shell)
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 /***************************************************************************/
266 void G4VInteractorManager::RemoveShell(G4Interactor a_shell)
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 /***************************************************************************/
279 void G4VInteractorManager::SetParentInteractor(G4Interactor a_interactor)
280 /***************************************************************************/
281 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
282 {
283   parentInteractor = a_interactor;
284 }
285 /***************************************************************************/
286 G4Interactor G4VInteractorManager::GetParentInteractor()
287 /***************************************************************************/
288 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
289 {
290   return parentInteractor;
291 }
292 /***************************************************************************/
293 void G4VInteractorManager::SetCreatedInteractor(G4Interactor a_interactor)
294 /***************************************************************************/
295 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
296 {
297   createdInteractor = a_interactor;
298 }
299 /***************************************************************************/
300 G4Interactor G4VInteractorManager::GetCreatedInteractor()
301 /***************************************************************************/
302 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
303 {
304   return createdInteractor;
305 }
306 /***************************************************************************/
307 void G4VInteractorManager::SetCreationString(char* a_string)
308 /***************************************************************************/
309 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
310 {
311   creationString = a_string;
312 }
313 /***************************************************************************/
314 char* G4VInteractorManager::GetCreationString()
315 /***************************************************************************/
316 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
317 {
318   return creationString;
319 }
320