Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 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((unsi 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[arg 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 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[arg 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; ++ar 94 argv[argi] = (char*)NewString(a_argv[a 95 } 96 } 97 } 98 } 99 /********************************************* 100 char** G4VInteractorManager::GetArguments(G4in 101 /********************************************* 102 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 103 { 104 if (a_argc != nullptr) *a_argc = argc; 105 return argv; 106 } 107 /********************************************* 108 void G4VInteractorManager::SetMainInteractor(G 109 /********************************************* 110 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 111 { 112 mainInteractor = a_main; 113 } 114 /********************************************* 115 G4Interactor G4VInteractorManager::GetMainInte 116 /********************************************* 117 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 118 { 119 return mainInteractor; 120 } 121 /********************************************* 122 void G4VInteractorManager::EnableSecondaryLoop 123 /********************************************* 124 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 125 { 126 secondaryLoopEnabled = true; 127 } 128 /********************************************* 129 void G4VInteractorManager::DisableSecondaryLoo 130 /********************************************* 131 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 132 { 133 secondaryLoopEnabled = false; 134 } 135 /********************************************* 136 void G4VInteractorManager::AddDispatcher(G4Dis 137 /********************************************* 138 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 139 { 140 if (a_dispatcher == nullptr) return; 141 if (std::find(dispatchers.cbegin(), dispatch 142 return; 143 dispatchers.push_back(a_dispatcher); 144 } 145 /********************************************* 146 void G4VInteractorManager::RemoveDispatcher(G4 147 /********************************************* 148 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 149 { 150 std::vector<G4DispatchFunction>::iterator it 151 for (it = dispatchers.begin(); it != dispatc 152 if (*it == a_dispatcher) { 153 dispatchers.erase(it); 154 break; 155 } 156 } 157 } 158 /********************************************* 159 void G4VInteractorManager::DispatchEvent(void* 160 /********************************************* 161 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 162 { 163 std::size_t dispatchern = dispatchers.size() 164 G4DispatchFunction func; 165 for (std::size_t count = 0; count < dispatch 166 func = dispatchers[count]; 167 if (func != nullptr) { 168 if (func(a_event)) return; 169 } 170 } 171 } 172 /********************************************* 173 void G4VInteractorManager::AddSecondaryLoopPre 174 /********************************************* 175 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 176 { 177 if (a_preAction == nullptr) return; 178 if (std::find(preActions.cbegin(), preAction 179 preActions.push_back(a_preAction); 180 } 181 /********************************************* 182 void G4VInteractorManager::SecondaryLoopPreAct 183 /********************************************* 184 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 185 { 186 std::size_t preActionn = preActions.size(); 187 for (std::size_t count = 0; count < preActio 188 if (preActions[count] != nullptr) preActio 189 } 190 } 191 /********************************************* 192 void G4VInteractorManager::AddSecondaryLoopPos 193 /********************************************* 194 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 195 { 196 if (a_postAction == nullptr) return; 197 if (std::find(postActions.cbegin(), postActi 198 return; 199 postActions.push_back(a_postAction); 200 } 201 /********************************************* 202 void G4VInteractorManager::SecondaryLoopPostAc 203 /********************************************* 204 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 205 { 206 std::size_t postActionn = postActions.size() 207 for (std::size_t count = 0; count < postActi 208 if (postActions[count] != nullptr) postAct 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 << "------------------------------- 222 G4cout << "You have entered a viewer secon 223 G4cout << "Quit it with an 'Escape' viewer 224 alreadyInSecondaryLoop = true; 225 exitSecondaryLoop = 0; 226 SecondaryLoopPreActions(); 227 // for(G4int count=0;count<shelln;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." 236 SecondaryLoopPostActions(); 237 } 238 } 239 /********************************************* 240 void G4VInteractorManager::RequireExitSecondar 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::GetExitSecondaryLo 251 /********************************************* 252 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 253 { 254 return exitSecondaryLoop; 255 } 256 /********************************************* 257 void G4VInteractorManager::AddShell(G4Interact 258 /********************************************* 259 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 260 { 261 if (a_shell == nullptr) return; 262 if (std::find(shells.cbegin(), shells.cend() 263 shells.push_back(a_shell); 264 } 265 /********************************************* 266 void G4VInteractorManager::RemoveShell(G4Inter 267 /********************************************* 268 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 269 { 270 std::vector<G4Interactor>::iterator it; 271 for (it = shells.begin(); it != shells.end() 272 if (*it == a_shell) { 273 shells.erase(it); 274 break; 275 } 276 } 277 } 278 /********************************************* 279 void G4VInteractorManager::SetParentInteractor 280 /********************************************* 281 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 282 { 283 parentInteractor = a_interactor; 284 } 285 /********************************************* 286 G4Interactor G4VInteractorManager::GetParentIn 287 /********************************************* 288 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 289 { 290 return parentInteractor; 291 } 292 /********************************************* 293 void G4VInteractorManager::SetCreatedInteracto 294 /********************************************* 295 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 296 { 297 createdInteractor = a_interactor; 298 } 299 /********************************************* 300 G4Interactor G4VInteractorManager::GetCreatedI 301 /********************************************* 302 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 303 { 304 return createdInteractor; 305 } 306 /********************************************* 307 void G4VInteractorManager::SetCreationString(c 308 /********************************************* 309 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 310 { 311 creationString = a_string; 312 } 313 /********************************************* 314 char* G4VInteractorManager::GetCreationString( 315 /********************************************* 316 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 317 { 318 return creationString; 319 } 320