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 | // $Id: G4VisManager.cc,v 1.121 2009/10/30 16:03:41 allison Exp $ |
---|
27 | // GEANT4 tag $Name: $ |
---|
28 | // |
---|
29 | // |
---|
30 | // GEANT4 Visualization Manager - John Allison 02/Jan/1996. |
---|
31 | |
---|
32 | #include "G4VisManager.hh" |
---|
33 | |
---|
34 | #include "G4VisCommands.hh" |
---|
35 | #include "G4VisCommandsCompound.hh" |
---|
36 | #include "G4VisCommandsGeometry.hh" |
---|
37 | #include "G4VisCommandsGeometrySet.hh" |
---|
38 | #include "G4VisCommandsScene.hh" |
---|
39 | #include "G4VisCommandsSceneAdd.hh" |
---|
40 | #include "G4VisCommandsSceneHandler.hh" |
---|
41 | #include "G4VisCommandsViewer.hh" |
---|
42 | #include "G4VisCommandsViewerSet.hh" |
---|
43 | #include "G4UImanager.hh" |
---|
44 | #include "G4VisStateDependent.hh" |
---|
45 | #include "G4UIdirectory.hh" |
---|
46 | #include "G4VisFeaturesOfFukuiRenderer.hh" |
---|
47 | #include "G4VisFeaturesOfDAWNFILE.hh" |
---|
48 | #include "G4VisFeaturesOfOpenGL.hh" |
---|
49 | #include "G4VisFeaturesOfOpenInventor.hh" |
---|
50 | #include "G4VGraphicsSystem.hh" |
---|
51 | #include "G4VSceneHandler.hh" |
---|
52 | #include "G4VViewer.hh" |
---|
53 | #include "G4VPhysicalVolume.hh" |
---|
54 | #include "G4LogicalVolume.hh" |
---|
55 | #include "G4VSolid.hh" |
---|
56 | #include "G4Vector3D.hh" |
---|
57 | #include "G4Point3D.hh" |
---|
58 | #include "G4RotationMatrix.hh" |
---|
59 | #include "G4Polyline.hh" |
---|
60 | #include "G4Polyhedron.hh" |
---|
61 | #include "G4NURBS.hh" |
---|
62 | #include "G4NullModel.hh" |
---|
63 | #include "G4ModelingParameters.hh" |
---|
64 | #include "G4TransportationManager.hh" |
---|
65 | #include "G4VisCommandModelCreate.hh" |
---|
66 | #include "G4VisCommandsListManager.hh" |
---|
67 | #include "G4VisModelManager.hh" |
---|
68 | #include "G4VModelFactory.hh" |
---|
69 | #include "G4VisFilterManager.hh" |
---|
70 | #include "G4VTrajectoryModel.hh" |
---|
71 | #include "G4TrajectoryDrawByCharge.hh" |
---|
72 | #include "Randomize.hh" |
---|
73 | #include "G4RunManager.hh" |
---|
74 | #include "G4EventManager.hh" |
---|
75 | #include "G4Run.hh" |
---|
76 | #include "G4Event.hh" |
---|
77 | #include <sstream> |
---|
78 | |
---|
79 | G4VisManager* G4VisManager::fpInstance = 0; |
---|
80 | |
---|
81 | G4VisManager::G4VisManager (): |
---|
82 | fVerbose (1), |
---|
83 | fInitialised (false), |
---|
84 | fpUserVisAction (0), |
---|
85 | fpGraphicsSystem (0), |
---|
86 | fpScene (0), |
---|
87 | fpSceneHandler (0), |
---|
88 | fpViewer (0), |
---|
89 | fVerbosity (all),//warnings), |
---|
90 | fpStateDependent (0), |
---|
91 | fEventRefreshing (false), |
---|
92 | fTransientsDrawnThisRun (false), |
---|
93 | fTransientsDrawnThisEvent (false), |
---|
94 | fEventKeepingSuspended (false), |
---|
95 | fKeptLastEvent (false), |
---|
96 | fpRequestedEvent (0), |
---|
97 | fAbortReviewKeptEvents (false) |
---|
98 | // All other objects use default constructors. |
---|
99 | { |
---|
100 | |
---|
101 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
102 | printf("G4VisManager::G4VisManager\n"); |
---|
103 | #endif |
---|
104 | fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories"); |
---|
105 | fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories"); |
---|
106 | fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits"); |
---|
107 | |
---|
108 | VerbosityGuidanceStrings.push_back |
---|
109 | ("Simple graded message scheme - digit or string (1st character defines):"); |
---|
110 | VerbosityGuidanceStrings.push_back |
---|
111 | (" 0) quiet, // Nothing is printed."); |
---|
112 | VerbosityGuidanceStrings.push_back |
---|
113 | (" 1) startup, // Startup and endup messages are printed..."); |
---|
114 | VerbosityGuidanceStrings.push_back |
---|
115 | (" 2) errors, // ...and errors..."); |
---|
116 | VerbosityGuidanceStrings.push_back |
---|
117 | (" 3) warnings, // ...and warnings..."); |
---|
118 | VerbosityGuidanceStrings.push_back |
---|
119 | (" 4) confirmations, // ...and confirming messages..."); |
---|
120 | VerbosityGuidanceStrings.push_back |
---|
121 | (" 5) parameters, // ...and parameters of scenes and views..."); |
---|
122 | VerbosityGuidanceStrings.push_back |
---|
123 | (" 6) all // ...and everything available."); |
---|
124 | |
---|
125 | if (fpInstance) { |
---|
126 | G4Exception |
---|
127 | ("G4VisManager: attempt to Construct more than one VisManager."); |
---|
128 | } |
---|
129 | else { |
---|
130 | |
---|
131 | fpInstance = this; |
---|
132 | SetConcreteInstance(this); |
---|
133 | |
---|
134 | fpStateDependent = new G4VisStateDependent (this); |
---|
135 | // No need to delete this; G4StateManager does this. |
---|
136 | |
---|
137 | if (fVerbosity >= startup) { |
---|
138 | G4cout << "Visualization Manager instantiating..." << G4endl; |
---|
139 | } |
---|
140 | |
---|
141 | // Note: The specific graphics systems must be instantiated in a |
---|
142 | // higher level library to avoid circular dependencies. Also, |
---|
143 | // some specifically need additional external libararies that the |
---|
144 | // user must supply. Therefore we ask the user to implement |
---|
145 | // RegisterGraphicsSystems() and RegisterModelFactories() |
---|
146 | // in a subclass. We have to wait for the subclass to instantiate |
---|
147 | // so RegisterGraphicsSystems() cannot be called from this |
---|
148 | // constructor; it is called from Initialise(). So we ask the |
---|
149 | // user: |
---|
150 | // (a) to write a subclass and implement RegisterGraphicsSystems() |
---|
151 | // and RegisterModelFactories(). See |
---|
152 | // visualization/include/G4VisExecutive.hh/icc as an example. |
---|
153 | // (b) instantiate the subclass. |
---|
154 | // (c) invoke the Initialise() method of the subclass. |
---|
155 | // For example: |
---|
156 | // ... |
---|
157 | // #ifdef G4VIS_USE |
---|
158 | // // Instantiate and initialise Visualization Manager. |
---|
159 | // G4VisManager* visManager = new G4VisExecutive; |
---|
160 | // visManager -> SetVerboseLevel (Verbose); |
---|
161 | // visManager -> Initialise (); |
---|
162 | // #endif |
---|
163 | // // (Don't forget to delete visManager;) |
---|
164 | // ... |
---|
165 | |
---|
166 | // Make top level command directory... |
---|
167 | G4UIcommand* directory; |
---|
168 | directory = new G4UIdirectory ("/vis/"); |
---|
169 | directory -> SetGuidance ("Visualization commands."); |
---|
170 | fDirectoryList.push_back (directory); |
---|
171 | |
---|
172 | // Instantiate top level basic commands |
---|
173 | G4VVisCommand::SetVisManager (this); // Sets shared pointer |
---|
174 | RegisterMessenger(new G4VisCommandVerbose); |
---|
175 | RegisterMessenger(new G4VisCommandInitialize); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | G4VisManager::~G4VisManager () { |
---|
180 | fpInstance = 0; |
---|
181 | size_t i; |
---|
182 | for (i = 0; i < fSceneList.size (); ++i) { |
---|
183 | delete fSceneList[i]; |
---|
184 | } |
---|
185 | for (i = 0; i < fAvailableSceneHandlers.size (); ++i) { |
---|
186 | delete fAvailableSceneHandlers[i]; |
---|
187 | } |
---|
188 | for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) { |
---|
189 | delete fAvailableGraphicsSystems[i]; |
---|
190 | } |
---|
191 | if (fVerbosity >= startup) { |
---|
192 | G4cout << "Graphics systems deleted." << G4endl; |
---|
193 | G4cout << "Visualization Manager deleting..." << G4endl; |
---|
194 | } |
---|
195 | for (i = 0; i < fMessengerList.size (); ++i) { |
---|
196 | delete fMessengerList[i]; |
---|
197 | } |
---|
198 | for (i = 0; i < fDirectoryList.size (); ++i) { |
---|
199 | delete fDirectoryList[i]; |
---|
200 | } |
---|
201 | |
---|
202 | delete fpTrajDrawModelMgr; |
---|
203 | delete fpTrajFilterMgr; |
---|
204 | delete fpHitFilterMgr; |
---|
205 | } |
---|
206 | |
---|
207 | G4VisManager* G4VisManager::GetInstance () { |
---|
208 | if (!fpInstance) { |
---|
209 | G4Exception |
---|
210 | ("G4VisManager::GetInstance: VisManager not yet instantiated!"); |
---|
211 | } |
---|
212 | return fpInstance; |
---|
213 | } |
---|
214 | |
---|
215 | void G4VisManager::Initialise () { |
---|
216 | |
---|
217 | if (fInitialised && fVerbosity >= warnings) { |
---|
218 | G4cout << "WARNING: G4VisManager::Initialise: already initialised." |
---|
219 | << G4endl; |
---|
220 | return; |
---|
221 | } |
---|
222 | |
---|
223 | if (fVerbosity >= startup) { |
---|
224 | G4cout << "Visualization Manager initialising..." << G4endl; |
---|
225 | } |
---|
226 | |
---|
227 | if (fVerbosity >= parameters) { |
---|
228 | G4cout << |
---|
229 | "\nYou have instantiated your own Visualization Manager, inheriting" |
---|
230 | "\n G4VisManager and implementing RegisterGraphicsSystems(), in which" |
---|
231 | "\n you should, normally, instantiate drivers which do not need" |
---|
232 | "\n external packages or libraries, and, optionally, drivers under" |
---|
233 | "\n control of environment variables." |
---|
234 | "\n Also you should implement RegisterModelFactories()." |
---|
235 | "\n See visualization/include/G4VisExecutive.hh/icc, for example." |
---|
236 | "\n In your main() you will have something like:" |
---|
237 | "\n #ifdef G4VIS_USE" |
---|
238 | "\n G4VisManager* visManager = new G4VisExecutive;" |
---|
239 | "\n visManager -> SetVerboseLevel (Verbose);" |
---|
240 | "\n visManager -> Initialize ();" |
---|
241 | "\n #endif" |
---|
242 | "\n (Don't forget to delete visManager;)" |
---|
243 | "\n" |
---|
244 | << G4endl; |
---|
245 | } |
---|
246 | |
---|
247 | if (fVerbosity >= startup) { |
---|
248 | G4cout << "Registering graphics systems..." << G4endl; |
---|
249 | } |
---|
250 | |
---|
251 | RegisterGraphicsSystems (); |
---|
252 | |
---|
253 | if (fVerbosity >= startup) { |
---|
254 | G4cout << |
---|
255 | "\nYou have successfully registered the following graphics systems." |
---|
256 | << G4endl; |
---|
257 | PrintAvailableGraphicsSystems (); |
---|
258 | G4cout << G4endl; |
---|
259 | } |
---|
260 | |
---|
261 | // Make command directories for commands instantiated in the |
---|
262 | // modeling subcategory... |
---|
263 | G4UIcommand* directory; |
---|
264 | directory = new G4UIdirectory ("/vis/modeling/"); |
---|
265 | directory -> SetGuidance ("Modeling commands."); |
---|
266 | fDirectoryList.push_back (directory); |
---|
267 | directory = new G4UIdirectory ("/vis/modeling/trajectories/"); |
---|
268 | directory -> SetGuidance ("Trajectory model commands."); |
---|
269 | fDirectoryList.push_back (directory); |
---|
270 | directory = new G4UIdirectory ("/vis/modeling/trajectories/create/"); |
---|
271 | directory -> SetGuidance ("Create trajectory models and messengers."); |
---|
272 | fDirectoryList.push_back (directory); |
---|
273 | |
---|
274 | // Filtering command directory |
---|
275 | directory = new G4UIdirectory ("/vis/filtering/"); |
---|
276 | directory -> SetGuidance ("Filtering commands."); |
---|
277 | fDirectoryList.push_back (directory); |
---|
278 | directory = new G4UIdirectory ("/vis/filtering/trajectories/"); |
---|
279 | directory -> SetGuidance ("Trajectory filtering commands."); |
---|
280 | fDirectoryList.push_back (directory); |
---|
281 | directory = new G4UIdirectory ("/vis/filtering/trajectories/create/"); |
---|
282 | directory -> SetGuidance ("Create trajectory filters and messengers."); |
---|
283 | fDirectoryList.push_back (directory); |
---|
284 | directory = new G4UIdirectory ("/vis/filtering/hits/"); |
---|
285 | directory -> SetGuidance ("Hit filtering commands."); |
---|
286 | fDirectoryList.push_back (directory); |
---|
287 | directory = new G4UIdirectory ("/vis/filtering/hits/create/"); |
---|
288 | directory -> SetGuidance ("Create hit filters and messengers."); |
---|
289 | fDirectoryList.push_back (directory); |
---|
290 | |
---|
291 | RegisterMessengers (); |
---|
292 | |
---|
293 | if (fVerbosity >= startup) { |
---|
294 | G4cout << "Registering model factories..." << G4endl; |
---|
295 | } |
---|
296 | |
---|
297 | RegisterModelFactories(); |
---|
298 | |
---|
299 | if (fVerbosity >= startup) { |
---|
300 | G4cout << |
---|
301 | "\nYou have successfully registered the following model factories." |
---|
302 | << G4endl; |
---|
303 | PrintAvailableModels (fVerbosity); |
---|
304 | G4cout << G4endl; |
---|
305 | } |
---|
306 | |
---|
307 | fInitialised = true; |
---|
308 | } |
---|
309 | |
---|
310 | void G4VisManager::Enable() { |
---|
311 | if (IsValidView ()) { |
---|
312 | if (fVerbosity >= confirmations) { |
---|
313 | G4cout << "G4VisManager::Enable: visualization enabled." << G4endl; |
---|
314 | } |
---|
315 | } |
---|
316 | else { |
---|
317 | if (fVerbosity >= warnings) { |
---|
318 | G4cout << |
---|
319 | "G4VisManager::Enable: WARNING: visualization remains disabled for" |
---|
320 | "\n above reasons. Rectifying with valid vis commands will" |
---|
321 | "\n automatically enable." |
---|
322 | << G4endl; |
---|
323 | } |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | void G4VisManager::Disable() { |
---|
328 | SetConcreteInstance(0); |
---|
329 | if (fVerbosity >= confirmations) { |
---|
330 | G4cout << |
---|
331 | "G4VisManager::Disable: visualization disabled." |
---|
332 | "\n The pointer returned by GetConcreteInstance will be zero." |
---|
333 | "\n Note that it will become enabled after some valid vis commands." |
---|
334 | << G4endl; |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | const G4GraphicsSystemList& G4VisManager::GetAvailableGraphicsSystems () { |
---|
339 | G4int nSystems = fAvailableGraphicsSystems.size (); |
---|
340 | if (nSystems == 0) { |
---|
341 | if (fVerbosity >= warnings) { |
---|
342 | G4cout << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no" |
---|
343 | "\n graphics system available!" |
---|
344 | "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set" |
---|
345 | "\n when you compiled/built the visualization code?" |
---|
346 | "\n 2) Did you instantiate your own Visualization Manager and forget" |
---|
347 | "\n to implement RegisterGraphicsSystems correctly?" |
---|
348 | "\n 3) You can register your own graphics system, e.g.," |
---|
349 | "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)" |
---|
350 | "\n after instantiating your vis manager and before" |
---|
351 | "\n visManager->Initialize()." |
---|
352 | << G4endl; |
---|
353 | } |
---|
354 | } |
---|
355 | return fAvailableGraphicsSystems; |
---|
356 | } |
---|
357 | |
---|
358 | G4bool G4VisManager::RegisterGraphicsSystem (G4VGraphicsSystem* pSystem) { |
---|
359 | G4bool happy = true; |
---|
360 | if (pSystem) { |
---|
361 | fAvailableGraphicsSystems.push_back (pSystem); |
---|
362 | if (fVerbosity >= confirmations) { |
---|
363 | G4cout << "G4VisManager::RegisterGraphicsSystem: " |
---|
364 | << pSystem -> GetName (); |
---|
365 | if (pSystem -> GetNickname () != "") { |
---|
366 | G4cout << " (" << pSystem -> GetNickname () << ")"; |
---|
367 | } |
---|
368 | G4cout << " registered." << G4endl; |
---|
369 | } |
---|
370 | } |
---|
371 | else { |
---|
372 | if (fVerbosity >= errors) { |
---|
373 | G4cout << "G4VisManager::RegisterGraphicsSystem: null pointer!" |
---|
374 | << G4endl; |
---|
375 | } |
---|
376 | happy=false; |
---|
377 | } |
---|
378 | return happy; |
---|
379 | } |
---|
380 | |
---|
381 | const G4VTrajectoryModel* |
---|
382 | G4VisManager::CurrentTrajDrawModel() const |
---|
383 | { |
---|
384 | assert (0 != fpTrajDrawModelMgr); |
---|
385 | |
---|
386 | const G4VTrajectoryModel* model = fpTrajDrawModelMgr->Current(); |
---|
387 | |
---|
388 | if (0 == model) { |
---|
389 | // No model was registered with the trajectory model manager. |
---|
390 | // Use G4TrajectoryDrawByCharge as a default. |
---|
391 | fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("AutoGenerated")); |
---|
392 | |
---|
393 | if (fVerbosity >= warnings) { |
---|
394 | G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl; |
---|
395 | G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl; |
---|
396 | } |
---|
397 | } |
---|
398 | |
---|
399 | model = fpTrajDrawModelMgr->Current(); |
---|
400 | assert (0 != model); // Should definitely exist now |
---|
401 | |
---|
402 | return model; |
---|
403 | } |
---|
404 | |
---|
405 | void G4VisManager::RegisterModel(G4VTrajectoryModel* model) |
---|
406 | { |
---|
407 | fpTrajDrawModelMgr->Register(model); |
---|
408 | } |
---|
409 | |
---|
410 | void |
---|
411 | G4VisManager::RegisterModelFactory(G4TrajDrawModelFactory* factory) |
---|
412 | { |
---|
413 | fpTrajDrawModelMgr->Register(factory); |
---|
414 | } |
---|
415 | |
---|
416 | void G4VisManager::RegisterModel(G4VFilter<G4VTrajectory>* model) |
---|
417 | { |
---|
418 | fpTrajFilterMgr->Register(model); |
---|
419 | } |
---|
420 | |
---|
421 | void |
---|
422 | G4VisManager::RegisterModelFactory(G4TrajFilterFactory* factory) |
---|
423 | { |
---|
424 | fpTrajFilterMgr->Register(factory); |
---|
425 | } |
---|
426 | |
---|
427 | void G4VisManager::RegisterModel(G4VFilter<G4VHit>* model) |
---|
428 | { |
---|
429 | fpHitFilterMgr->Register(model); |
---|
430 | } |
---|
431 | |
---|
432 | void |
---|
433 | G4VisManager::RegisterModelFactory(G4HitFilterFactory* factory) |
---|
434 | { |
---|
435 | fpHitFilterMgr->Register(factory); |
---|
436 | } |
---|
437 | |
---|
438 | void G4VisManager::SelectTrajectoryModel(const G4String& model) |
---|
439 | { |
---|
440 | fpTrajDrawModelMgr->SetCurrent(model); |
---|
441 | } |
---|
442 | |
---|
443 | void G4VisManager::Draw (const G4Circle& circle, |
---|
444 | const G4Transform3D& objectTransform) { |
---|
445 | if (IsValidView ()) { |
---|
446 | ClearTransientStoreIfMarked(); |
---|
447 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
448 | fpSceneHandler -> AddPrimitive (circle); |
---|
449 | fpSceneHandler -> EndPrimitives (); |
---|
450 | } |
---|
451 | } |
---|
452 | |
---|
453 | void G4VisManager::Draw (const G4NURBS& nurbs, |
---|
454 | const G4Transform3D& objectTransform) { |
---|
455 | if (IsValidView ()) { |
---|
456 | ClearTransientStoreIfMarked(); |
---|
457 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
458 | fpSceneHandler -> AddPrimitive (nurbs); |
---|
459 | fpSceneHandler -> EndPrimitives (); |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | void G4VisManager::Draw (const G4Polyhedron& polyhedron, |
---|
464 | const G4Transform3D& objectTransform) { |
---|
465 | if (IsValidView ()) { |
---|
466 | ClearTransientStoreIfMarked(); |
---|
467 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
468 | fpSceneHandler -> AddPrimitive (polyhedron); |
---|
469 | fpSceneHandler -> EndPrimitives (); |
---|
470 | } |
---|
471 | } |
---|
472 | |
---|
473 | void G4VisManager::Draw (const G4Polyline& line, |
---|
474 | const G4Transform3D& objectTransform) { |
---|
475 | if (IsValidView ()) { |
---|
476 | ClearTransientStoreIfMarked(); |
---|
477 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
478 | fpSceneHandler -> AddPrimitive (line); |
---|
479 | fpSceneHandler -> EndPrimitives (); |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | void G4VisManager::Draw (const G4Polymarker& polymarker, |
---|
484 | const G4Transform3D& objectTransform) { |
---|
485 | if (IsValidView ()) { |
---|
486 | ClearTransientStoreIfMarked(); |
---|
487 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
488 | fpSceneHandler -> AddPrimitive (polymarker); |
---|
489 | fpSceneHandler -> EndPrimitives (); |
---|
490 | } |
---|
491 | } |
---|
492 | |
---|
493 | void G4VisManager::Draw (const G4Scale& scale, |
---|
494 | const G4Transform3D& objectTransform) { |
---|
495 | if (IsValidView ()) { |
---|
496 | ClearTransientStoreIfMarked(); |
---|
497 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
498 | fpSceneHandler -> AddPrimitive (scale); |
---|
499 | fpSceneHandler -> EndPrimitives (); |
---|
500 | } |
---|
501 | } |
---|
502 | |
---|
503 | void G4VisManager::Draw (const G4Square& square, |
---|
504 | const G4Transform3D& objectTransform) { |
---|
505 | if (IsValidView ()) { |
---|
506 | ClearTransientStoreIfMarked(); |
---|
507 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
508 | fpSceneHandler -> AddPrimitive (square); |
---|
509 | fpSceneHandler -> EndPrimitives (); |
---|
510 | } |
---|
511 | } |
---|
512 | |
---|
513 | void G4VisManager::Draw (const G4Text& text, |
---|
514 | const G4Transform3D& objectTransform) { |
---|
515 | if (IsValidView ()) { |
---|
516 | ClearTransientStoreIfMarked(); |
---|
517 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
518 | fpSceneHandler -> AddPrimitive (text); |
---|
519 | fpSceneHandler -> EndPrimitives (); |
---|
520 | } |
---|
521 | } |
---|
522 | |
---|
523 | void G4VisManager::Draw2D (const G4Circle& circle, |
---|
524 | const G4Transform3D& objectTransform) |
---|
525 | { |
---|
526 | if (IsValidView()) { |
---|
527 | ClearTransientStoreIfMarked(); |
---|
528 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
529 | fpSceneHandler -> AddPrimitive(circle); |
---|
530 | fpSceneHandler -> EndPrimitives2D(); |
---|
531 | } |
---|
532 | } |
---|
533 | |
---|
534 | void G4VisManager::Draw2D (const G4NURBS& nurbs, |
---|
535 | const G4Transform3D& objectTransform) |
---|
536 | { |
---|
537 | if (IsValidView()) { |
---|
538 | ClearTransientStoreIfMarked(); |
---|
539 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
540 | fpSceneHandler -> AddPrimitive(nurbs); |
---|
541 | fpSceneHandler -> EndPrimitives2D(); |
---|
542 | } |
---|
543 | } |
---|
544 | |
---|
545 | void G4VisManager::Draw2D (const G4Polyhedron& polyhedron, |
---|
546 | const G4Transform3D& objectTransform) |
---|
547 | { |
---|
548 | if (IsValidView()) { |
---|
549 | ClearTransientStoreIfMarked(); |
---|
550 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
551 | fpSceneHandler -> AddPrimitive(polyhedron); |
---|
552 | fpSceneHandler -> EndPrimitives2D(); |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | void G4VisManager::Draw2D (const G4Polyline& line, |
---|
557 | const G4Transform3D& objectTransform) |
---|
558 | { |
---|
559 | if (IsValidView()) { |
---|
560 | ClearTransientStoreIfMarked(); |
---|
561 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
562 | fpSceneHandler -> AddPrimitive(line); |
---|
563 | fpSceneHandler -> EndPrimitives2D(); |
---|
564 | } |
---|
565 | } |
---|
566 | |
---|
567 | void G4VisManager::Draw2D (const G4Polymarker& polymarker, |
---|
568 | const G4Transform3D& objectTransform) |
---|
569 | { |
---|
570 | if (IsValidView()) { |
---|
571 | ClearTransientStoreIfMarked(); |
---|
572 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
573 | fpSceneHandler -> AddPrimitive(polymarker); |
---|
574 | fpSceneHandler -> EndPrimitives2D(); |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | void G4VisManager::Draw2D (const G4Square& square, |
---|
579 | const G4Transform3D& objectTransform) |
---|
580 | { |
---|
581 | if (IsValidView()) { |
---|
582 | ClearTransientStoreIfMarked(); |
---|
583 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
584 | fpSceneHandler -> AddPrimitive(square); |
---|
585 | fpSceneHandler -> EndPrimitives2D(); |
---|
586 | } |
---|
587 | } |
---|
588 | |
---|
589 | void G4VisManager::Draw2D (const G4Text& text, |
---|
590 | const G4Transform3D& objectTransform) |
---|
591 | { |
---|
592 | if (IsValidView()) { |
---|
593 | ClearTransientStoreIfMarked(); |
---|
594 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
595 | fpSceneHandler -> AddPrimitive(text); |
---|
596 | fpSceneHandler -> EndPrimitives2D(); |
---|
597 | } |
---|
598 | } |
---|
599 | |
---|
600 | void G4VisManager::Draw (const G4VHit& hit) { |
---|
601 | if (IsValidView ()) { |
---|
602 | ClearTransientStoreIfMarked(); |
---|
603 | fpSceneHandler -> AddCompound (hit); |
---|
604 | } |
---|
605 | } |
---|
606 | |
---|
607 | void G4VisManager::Draw (const G4VTrajectory& traj, |
---|
608 | G4int i_mode) { |
---|
609 | if (IsValidView ()) { |
---|
610 | ClearTransientStoreIfMarked(); |
---|
611 | fpSceneHandler -> SetModel (&dummyTrajectoriesModel); |
---|
612 | dummyTrajectoriesModel.SetDrawingMode(i_mode); |
---|
613 | fpSceneHandler -> AddCompound (traj); |
---|
614 | } |
---|
615 | } |
---|
616 | |
---|
617 | void G4VisManager::Draw (const G4LogicalVolume& logicalVol, |
---|
618 | const G4VisAttributes& attribs, |
---|
619 | const G4Transform3D& objectTransform) { |
---|
620 | // Find corresponding solid. |
---|
621 | G4VSolid* pSol = logicalVol.GetSolid (); |
---|
622 | Draw (*pSol, attribs, objectTransform); |
---|
623 | } |
---|
624 | |
---|
625 | void G4VisManager::Draw (const G4VSolid& solid, |
---|
626 | const G4VisAttributes& attribs, |
---|
627 | const G4Transform3D& objectTransform) { |
---|
628 | if (IsValidView ()) { |
---|
629 | ClearTransientStoreIfMarked(); |
---|
630 | fpSceneHandler -> PreAddSolid (objectTransform, attribs); |
---|
631 | solid.DescribeYourselfTo (*fpSceneHandler); |
---|
632 | fpSceneHandler -> PostAddSolid (); |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol, |
---|
637 | const G4VisAttributes& attribs, |
---|
638 | const G4Transform3D& objectTransform) { |
---|
639 | // Find corresponding logical volume and solid. |
---|
640 | G4LogicalVolume* pLV = physicalVol.GetLogicalVolume (); |
---|
641 | G4VSolid* pSol = pLV -> GetSolid (); |
---|
642 | Draw (*pSol, attribs, objectTransform); |
---|
643 | } |
---|
644 | |
---|
645 | void G4VisManager::CreateSceneHandler (G4String name) { |
---|
646 | if (!fInitialised) Initialise (); |
---|
647 | if (fpGraphicsSystem) { |
---|
648 | G4VSceneHandler* pSceneHandler = |
---|
649 | fpGraphicsSystem -> CreateSceneHandler (name); |
---|
650 | if (pSceneHandler) { |
---|
651 | fAvailableSceneHandlers.push_back (pSceneHandler); |
---|
652 | fpSceneHandler = pSceneHandler; // Make current. |
---|
653 | } |
---|
654 | else { |
---|
655 | if(fVerbosity >= errors) { |
---|
656 | G4cout << "ERROR in G4VisManager::CreateSceneHandler during " |
---|
657 | << fpGraphicsSystem -> GetName () |
---|
658 | << " scene handler creation.\n No action taken." |
---|
659 | << G4endl; |
---|
660 | } |
---|
661 | } |
---|
662 | } |
---|
663 | else PrintInvalidPointers (); |
---|
664 | } |
---|
665 | |
---|
666 | void G4VisManager::CreateViewer (G4String name,G4String XGeometry) { |
---|
667 | printf("G4VisManager::CreateViewer -------------------- %s ----%s\n",name.c_str(),XGeometry.c_str()); |
---|
668 | |
---|
669 | if (!fInitialised) Initialise (); |
---|
670 | |
---|
671 | if (!fpSceneHandler) { |
---|
672 | PrintInvalidPointers (); |
---|
673 | return; |
---|
674 | } |
---|
675 | |
---|
676 | printf("G4VisManager::CreateViewer 1-------------------- %s ----%s\n",name.c_str(),XGeometry.c_str()); |
---|
677 | G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name); |
---|
678 | printf("G4VisManager::CreateViewer 2-------------------- %s ----%s\n",name.c_str(),XGeometry.c_str()); |
---|
679 | |
---|
680 | if (!p) { |
---|
681 | if (fVerbosity >= errors) { |
---|
682 | G4cout << "ERROR in G4VisManager::CreateViewer during " |
---|
683 | << fpGraphicsSystem -> GetName () |
---|
684 | << " viewer creation.\n No action taken." |
---|
685 | << G4endl; |
---|
686 | } |
---|
687 | return; |
---|
688 | } |
---|
689 | |
---|
690 | if (p -> GetViewId() < 0) { |
---|
691 | if (fVerbosity >= errors) { |
---|
692 | G4cout << "ERROR in G4VisManager::CreateViewer during " |
---|
693 | << fpGraphicsSystem -> GetName () |
---|
694 | << " viewer initialisation.\n No action taken." |
---|
695 | << G4endl; |
---|
696 | } |
---|
697 | return; |
---|
698 | } |
---|
699 | |
---|
700 | // Viewer is created, now we can set geometry parameters |
---|
701 | // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there! |
---|
702 | |
---|
703 | G4ViewParameters initialvp = p -> GetViewParameters(); |
---|
704 | initialvp.SetXGeometryString(XGeometry); //parse string and store parameters |
---|
705 | p -> SetViewParameters(initialvp); |
---|
706 | p -> Initialise (); // (Viewer itself may change view parameters further.) |
---|
707 | |
---|
708 | fpViewer = p; // Make current. |
---|
709 | fpSceneHandler -> AddViewerToList (fpViewer); |
---|
710 | fpSceneHandler -> SetCurrentViewer (fpViewer); |
---|
711 | if (fVerbosity >= confirmations) { |
---|
712 | G4cout << "G4VisManager::CreateViewer: new viewer created." |
---|
713 | << G4endl; |
---|
714 | } |
---|
715 | |
---|
716 | const G4ViewParameters& vp = fpViewer->GetViewParameters(); |
---|
717 | if (fVerbosity >= parameters) { |
---|
718 | G4cout << " view parameters are:\n " << vp << G4endl; |
---|
719 | } |
---|
720 | |
---|
721 | if (vp.IsCulling () && vp.IsCullingInvisible ()) { |
---|
722 | static G4bool warned = false; |
---|
723 | if (fVerbosity >= confirmations) { |
---|
724 | if (!warned) { |
---|
725 | G4cout << |
---|
726 | "NOTE: objects with visibility flag set to \"false\"" |
---|
727 | " will not be drawn!" |
---|
728 | "\n \"/vis/viewer/set/culling global false\" to Draw such objects." |
---|
729 | "\n Also see other \"/vis/viewer/set\" commands." |
---|
730 | << G4endl; |
---|
731 | warned = true; |
---|
732 | } |
---|
733 | } |
---|
734 | } |
---|
735 | if (vp.IsCullingCovered ()) { |
---|
736 | static G4bool warned = false; |
---|
737 | if (fVerbosity >= warnings) { |
---|
738 | if (!warned) { |
---|
739 | G4cout << |
---|
740 | "WARNING: covered objects in solid mode will not be rendered!" |
---|
741 | "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this." |
---|
742 | "\n Also see other \"/vis/viewer/set\" commands." |
---|
743 | << G4endl; |
---|
744 | warned = true; |
---|
745 | } |
---|
746 | } |
---|
747 | } |
---|
748 | } |
---|
749 | |
---|
750 | void G4VisManager::GeometryHasChanged () { |
---|
751 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
752 | printf("G4VisManager::GeometryHasChanged \n"); |
---|
753 | #endif |
---|
754 | if (fVerbosity >= confirmations) { |
---|
755 | G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl; |
---|
756 | } |
---|
757 | |
---|
758 | // Change the world... |
---|
759 | G4VPhysicalVolume* pWorld = |
---|
760 | G4TransportationManager::GetTransportationManager () |
---|
761 | -> GetNavigatorForTracking () -> GetWorldVolume (); |
---|
762 | if (!pWorld) { |
---|
763 | if (fVerbosity >= warnings) { |
---|
764 | G4cout << "WARNING: There is no world volume!" << G4endl; |
---|
765 | } |
---|
766 | } |
---|
767 | |
---|
768 | // Check scenes. |
---|
769 | G4SceneList& sceneList = fSceneList; |
---|
770 | G4int iScene, nScenes = sceneList.size (); |
---|
771 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
772 | G4Scene* pScene = sceneList [iScene]; |
---|
773 | std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList (); |
---|
774 | |
---|
775 | if (modelList.size ()) { |
---|
776 | G4bool modelInvalid; |
---|
777 | do { // Remove, if required, one at a time. |
---|
778 | modelInvalid = false; |
---|
779 | std::vector<G4VModel*>::iterator iterModel; |
---|
780 | for (iterModel = modelList.begin(); |
---|
781 | iterModel != modelList.end(); |
---|
782 | ++iterModel) { |
---|
783 | modelInvalid = !((*iterModel) -> Validate (fVerbosity >= warnings)); |
---|
784 | if (modelInvalid) { |
---|
785 | // Model invalid - remove and break. |
---|
786 | if (fVerbosity >= warnings) { |
---|
787 | G4cout << "WARNING: Model \"" |
---|
788 | << (*iterModel) -> GetGlobalDescription () |
---|
789 | << |
---|
790 | "\" is no longer valid - being removed\n from scene \"" |
---|
791 | << pScene -> GetName () << "\"" |
---|
792 | << G4endl; |
---|
793 | } |
---|
794 | modelList.erase (iterModel); |
---|
795 | break; |
---|
796 | } |
---|
797 | } |
---|
798 | } while (modelInvalid); |
---|
799 | |
---|
800 | if (modelList.size () == 0) { |
---|
801 | if (fVerbosity >= warnings) { |
---|
802 | G4cout << "WARNING: No models left in this scene \"" |
---|
803 | << pScene -> GetName () |
---|
804 | << "\"." |
---|
805 | << G4endl; |
---|
806 | } |
---|
807 | } |
---|
808 | else { |
---|
809 | pScene->CalculateExtent(); |
---|
810 | G4UImanager::GetUIpointer () -> |
---|
811 | ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName())); |
---|
812 | } |
---|
813 | } |
---|
814 | } |
---|
815 | |
---|
816 | // Check the manager's current scene... |
---|
817 | if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) { |
---|
818 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
819 | printf("G4VisManager::GeometryHasChanged NO MODELS\n"); |
---|
820 | #endif |
---|
821 | if (fVerbosity >= warnings) { |
---|
822 | G4cout << "WARNING: The current scene \"" |
---|
823 | << fpScene -> GetName () |
---|
824 | << "\" has no models." |
---|
825 | << G4endl; |
---|
826 | } |
---|
827 | } |
---|
828 | |
---|
829 | } |
---|
830 | void G4VisManager::NotifyHandlers () { |
---|
831 | |
---|
832 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
833 | printf("G4VisManager::NotifyHandlers \n"); |
---|
834 | #endif |
---|
835 | if (fVerbosity >= confirmations) { |
---|
836 | G4cout << "G4VisManager::NotifyHandler() called." << G4endl; |
---|
837 | } |
---|
838 | |
---|
839 | // Check scenes. |
---|
840 | G4SceneList& sceneList = fSceneList; |
---|
841 | G4int iScene, nScenes = sceneList.size (); |
---|
842 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
843 | G4Scene* pScene = sceneList [iScene]; |
---|
844 | std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList (); |
---|
845 | |
---|
846 | if (modelList.size ()) { |
---|
847 | pScene->CalculateExtent(); |
---|
848 | G4UImanager::GetUIpointer () -> |
---|
849 | ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName())); |
---|
850 | } |
---|
851 | } |
---|
852 | |
---|
853 | // Check the manager's current scene... |
---|
854 | if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) { |
---|
855 | if (fVerbosity >= warnings) { |
---|
856 | G4cout << "WARNING: The current scene \"" |
---|
857 | << fpScene -> GetName () |
---|
858 | << "\" has no models." |
---|
859 | << G4endl; |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
864 | printf("G4VisManager::NotifyHandlers END\n"); |
---|
865 | #endif |
---|
866 | } |
---|
867 | |
---|
868 | G4bool G4VisManager::FilterTrajectory(const G4VTrajectory& trajectory) |
---|
869 | { |
---|
870 | return fpTrajFilterMgr->Accept(trajectory); |
---|
871 | } |
---|
872 | |
---|
873 | G4bool G4VisManager::FilterHit(const G4VHit& hit) |
---|
874 | { |
---|
875 | return fpHitFilterMgr->Accept(hit); |
---|
876 | } |
---|
877 | |
---|
878 | void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory, G4int i_mode) |
---|
879 | { |
---|
880 | G4bool visible(true); |
---|
881 | |
---|
882 | // See if trajectory passes filter |
---|
883 | G4bool passed = FilterTrajectory(trajectory); |
---|
884 | |
---|
885 | if (!passed) { |
---|
886 | // Draw invisible trajectory if trajectory failed filter and |
---|
887 | // are filtering in soft mode |
---|
888 | if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false; |
---|
889 | else {return;} |
---|
890 | } |
---|
891 | |
---|
892 | // Go on to draw trajectory |
---|
893 | assert (0 != fpTrajDrawModelMgr); |
---|
894 | |
---|
895 | const G4VTrajectoryModel* model = CurrentTrajDrawModel(); |
---|
896 | |
---|
897 | assert (0 != model); // Should exist |
---|
898 | |
---|
899 | model->Draw(trajectory, i_mode, visible); |
---|
900 | } |
---|
901 | |
---|
902 | void G4VisManager::SetUserAction |
---|
903 | (G4VUserVisAction* pVisAction, |
---|
904 | const G4VisExtent& extent) { |
---|
905 | fpUserVisAction = pVisAction; |
---|
906 | fUserVisActionExtent = extent; |
---|
907 | if (extent.GetExtentRadius() <= 0.) { |
---|
908 | if (fVerbosity >= warnings) { |
---|
909 | G4cout << |
---|
910 | "WARNING: No extent set for user vis action. (You may" |
---|
911 | "\n set it later when adding with /vis/scene/add/userAction.)" |
---|
912 | << G4endl; |
---|
913 | } |
---|
914 | } |
---|
915 | } |
---|
916 | |
---|
917 | void G4VisManager::SetCurrentScene (G4Scene* pScene) { |
---|
918 | if (pScene != fpScene) { |
---|
919 | // A change of scene. Therefore reset transients drawn flags. All |
---|
920 | // memory of previous transient proceessing thereby erased... |
---|
921 | ResetTransientsDrawnFlags(); |
---|
922 | } |
---|
923 | fpScene = pScene; |
---|
924 | } |
---|
925 | |
---|
926 | void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) { |
---|
927 | fpGraphicsSystem = pSystem; |
---|
928 | if (fVerbosity >= confirmations) { |
---|
929 | G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now " |
---|
930 | << pSystem -> GetName () << G4endl; |
---|
931 | } |
---|
932 | // If current scene handler is of same graphics system, leave unchanged. |
---|
933 | // Else find the most recent scene handler of same graphics system. |
---|
934 | // Or clear pointers. |
---|
935 | if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) { |
---|
936 | const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers; |
---|
937 | G4int nSH = sceneHandlerList.size (); // No. of scene handlers. |
---|
938 | G4int iSH; |
---|
939 | for (iSH = nSH - 1; iSH >= 0; iSH--) { |
---|
940 | if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break; |
---|
941 | } |
---|
942 | if (iSH >= 0) { |
---|
943 | fpSceneHandler = sceneHandlerList [iSH]; |
---|
944 | if (fVerbosity >= confirmations) { |
---|
945 | G4cout << " Scene Handler now " |
---|
946 | << fpSceneHandler -> GetName () << G4endl; |
---|
947 | } |
---|
948 | if (fpScene != fpSceneHandler -> GetScene ()) { |
---|
949 | fpScene = fpSceneHandler -> GetScene (); |
---|
950 | if (fVerbosity >= confirmations) { |
---|
951 | G4cout << " Scene now \"" |
---|
952 | << fpScene -> GetName () << "\"" << G4endl; |
---|
953 | } |
---|
954 | } |
---|
955 | const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList (); |
---|
956 | if (viewerList.size ()) { |
---|
957 | fpViewer = viewerList [0]; |
---|
958 | if (fVerbosity >= confirmations) { |
---|
959 | G4cout << " Viewer now " << fpViewer -> GetName () << G4endl; |
---|
960 | } |
---|
961 | } |
---|
962 | else { |
---|
963 | fpViewer = 0; |
---|
964 | } |
---|
965 | } |
---|
966 | else { |
---|
967 | fpSceneHandler = 0; |
---|
968 | fpViewer = 0; |
---|
969 | } |
---|
970 | } |
---|
971 | } |
---|
972 | |
---|
973 | void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) { |
---|
974 | fpSceneHandler = pSceneHandler; |
---|
975 | if (fVerbosity >= confirmations) { |
---|
976 | G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \"" |
---|
977 | << pSceneHandler -> GetName () << "\"" << G4endl; |
---|
978 | } |
---|
979 | if (fpScene != fpSceneHandler -> GetScene ()) { |
---|
980 | fpScene = fpSceneHandler -> GetScene (); |
---|
981 | if (fVerbosity >= confirmations) { |
---|
982 | G4cout << " Scene now \"" |
---|
983 | << fpScene -> GetName () << "\"" << G4endl; |
---|
984 | } |
---|
985 | } |
---|
986 | if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) { |
---|
987 | fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem (); |
---|
988 | if (fVerbosity >= confirmations) { |
---|
989 | G4cout << " Graphics system now \"" |
---|
990 | << fpGraphicsSystem -> GetName () << "\"" << G4endl; |
---|
991 | } |
---|
992 | } |
---|
993 | const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList (); |
---|
994 | G4int nViewers = viewerList.size (); |
---|
995 | if (nViewers) { |
---|
996 | G4int iViewer; |
---|
997 | for (iViewer = 0; iViewer < nViewers; iViewer++) { |
---|
998 | if (fpViewer == viewerList [iViewer]) break; |
---|
999 | } |
---|
1000 | if (iViewer >= nViewers) { |
---|
1001 | fpViewer = viewerList [0]; |
---|
1002 | if (fVerbosity >= confirmations) { |
---|
1003 | G4cout << " Viewer now \"" << fpViewer -> GetName () << "\"" |
---|
1004 | << G4endl; |
---|
1005 | } |
---|
1006 | } |
---|
1007 | IsValidView (); // Checks. |
---|
1008 | } |
---|
1009 | else { |
---|
1010 | fpViewer = 0; |
---|
1011 | if (fVerbosity >= warnings) { |
---|
1012 | G4cout << |
---|
1013 | "WARNING: No viewers for this scene handler - please create one." |
---|
1014 | << G4endl; |
---|
1015 | } |
---|
1016 | } |
---|
1017 | } |
---|
1018 | |
---|
1019 | void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) { |
---|
1020 | fpViewer = pViewer; |
---|
1021 | if (fVerbosity >= confirmations) { |
---|
1022 | G4cout << "G4VisManager::SetCurrentViewer: viewer now " |
---|
1023 | << pViewer -> GetName () |
---|
1024 | << G4endl; |
---|
1025 | } |
---|
1026 | fpSceneHandler = fpViewer -> GetSceneHandler (); |
---|
1027 | fpSceneHandler -> SetCurrentViewer (pViewer); |
---|
1028 | fpScene = fpSceneHandler -> GetScene (); |
---|
1029 | fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem (); |
---|
1030 | IsValidView (); // Checks. |
---|
1031 | } |
---|
1032 | |
---|
1033 | void G4VisManager::RegisterMessengers () { |
---|
1034 | |
---|
1035 | // Instantiate individual messengers/commands (often - but not |
---|
1036 | // always - one command per messenger). |
---|
1037 | |
---|
1038 | G4UIcommand* directory; |
---|
1039 | |
---|
1040 | // Top level commands... |
---|
1041 | RegisterMessenger(new G4VisCommandAbortReviewKeptEvents); |
---|
1042 | RegisterMessenger(new G4VisCommandEnable); |
---|
1043 | RegisterMessenger(new G4VisCommandList); |
---|
1044 | RegisterMessenger(new G4VisCommandReviewKeptEvents); |
---|
1045 | |
---|
1046 | // Compound commands... |
---|
1047 | RegisterMessenger(new G4VisCommandDrawTree); |
---|
1048 | RegisterMessenger(new G4VisCommandDrawView); |
---|
1049 | RegisterMessenger(new G4VisCommandDrawVolume); |
---|
1050 | RegisterMessenger(new G4VisCommandOpen); |
---|
1051 | RegisterMessenger(new G4VisCommandSpecify); |
---|
1052 | |
---|
1053 | directory = new G4UIdirectory ("/vis/geometry/"); |
---|
1054 | directory -> SetGuidance("Operations on vis attributes of Geant4 geometry."); |
---|
1055 | fDirectoryList.push_back (directory); |
---|
1056 | RegisterMessenger(new G4VisCommandGeometryList); |
---|
1057 | RegisterMessenger(new G4VisCommandGeometryRestore); |
---|
1058 | |
---|
1059 | directory = new G4UIdirectory ("/vis/geometry/set/"); |
---|
1060 | directory -> SetGuidance("Set vis attributes of Geant4 geometry."); |
---|
1061 | fDirectoryList.push_back (directory); |
---|
1062 | RegisterMessenger(new G4VisCommandGeometrySetColour); |
---|
1063 | RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible); |
---|
1064 | RegisterMessenger(new G4VisCommandGeometrySetLineStyle); |
---|
1065 | RegisterMessenger(new G4VisCommandGeometrySetLineWidth); |
---|
1066 | RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible); |
---|
1067 | RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle); |
---|
1068 | RegisterMessenger(new G4VisCommandGeometrySetForceSolid); |
---|
1069 | RegisterMessenger(new G4VisCommandGeometrySetForceWireframe); |
---|
1070 | RegisterMessenger(new G4VisCommandGeometrySetVisibility); |
---|
1071 | |
---|
1072 | directory = new G4UIdirectory ("/vis/scene/"); |
---|
1073 | directory -> SetGuidance ("Operations on Geant4 scenes."); |
---|
1074 | fDirectoryList.push_back (directory); |
---|
1075 | RegisterMessenger(new G4VisCommandSceneCreate); |
---|
1076 | RegisterMessenger(new G4VisCommandSceneEndOfEventAction); |
---|
1077 | RegisterMessenger(new G4VisCommandSceneEndOfRunAction); |
---|
1078 | RegisterMessenger(new G4VisCommandSceneList); |
---|
1079 | RegisterMessenger(new G4VisCommandSceneNotifyHandlers); |
---|
1080 | RegisterMessenger(new G4VisCommandSceneSelect); |
---|
1081 | |
---|
1082 | directory = new G4UIdirectory ("/vis/scene/add/"); |
---|
1083 | directory -> SetGuidance ("Add model to current scene."); |
---|
1084 | fDirectoryList.push_back (directory); |
---|
1085 | RegisterMessenger(new G4VisCommandSceneAddAxes); |
---|
1086 | RegisterMessenger(new G4VisCommandSceneAddEventID); |
---|
1087 | RegisterMessenger(new G4VisCommandSceneAddGhosts); |
---|
1088 | RegisterMessenger(new G4VisCommandSceneAddHits); |
---|
1089 | RegisterMessenger(new G4VisCommandSceneAddLogicalVolume); |
---|
1090 | RegisterMessenger(new G4VisCommandSceneAddLogo); |
---|
1091 | RegisterMessenger(new G4VisCommandSceneAddPSHits); |
---|
1092 | RegisterMessenger(new G4VisCommandSceneAddScale); |
---|
1093 | RegisterMessenger(new G4VisCommandSceneAddText); |
---|
1094 | RegisterMessenger(new G4VisCommandSceneAddTrajectories); |
---|
1095 | RegisterMessenger(new G4VisCommandSceneAddUserAction); |
---|
1096 | RegisterMessenger(new G4VisCommandSceneAddVolume); |
---|
1097 | |
---|
1098 | directory = new G4UIdirectory ("/vis/sceneHandler/"); |
---|
1099 | directory -> SetGuidance ("Operations on Geant4 scene handlers."); |
---|
1100 | fDirectoryList.push_back (directory); |
---|
1101 | RegisterMessenger(new G4VisCommandSceneHandlerAttach); |
---|
1102 | RegisterMessenger(new G4VisCommandSceneHandlerCreate); |
---|
1103 | RegisterMessenger(new G4VisCommandSceneHandlerList); |
---|
1104 | RegisterMessenger(new G4VisCommandSceneHandlerSelect); |
---|
1105 | |
---|
1106 | directory = new G4UIdirectory ("/vis/viewer/"); |
---|
1107 | directory -> SetGuidance ("Operations on Geant4 viewers."); |
---|
1108 | fDirectoryList.push_back (directory); |
---|
1109 | RegisterMessenger(new G4VisCommandViewerAddCutawayPlane); |
---|
1110 | RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane); |
---|
1111 | RegisterMessenger(new G4VisCommandViewerClear); |
---|
1112 | RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes); |
---|
1113 | RegisterMessenger(new G4VisCommandViewerClearTransients); |
---|
1114 | RegisterMessenger(new G4VisCommandViewerClone); |
---|
1115 | RegisterMessenger(new G4VisCommandViewerCreate); |
---|
1116 | RegisterMessenger(new G4VisCommandViewerDolly); |
---|
1117 | RegisterMessenger(new G4VisCommandViewerFlush); |
---|
1118 | RegisterMessenger(new G4VisCommandViewerList); |
---|
1119 | RegisterMessenger(new G4VisCommandViewerPan); |
---|
1120 | RegisterMessenger(new G4VisCommandViewerRebuild); |
---|
1121 | RegisterMessenger(new G4VisCommandViewerRefresh); |
---|
1122 | RegisterMessenger(new G4VisCommandViewerReset); |
---|
1123 | RegisterMessenger(new G4VisCommandViewerScale); |
---|
1124 | RegisterMessenger(new G4VisCommandViewerSelect); |
---|
1125 | RegisterMessenger(new G4VisCommandViewerUpdate); |
---|
1126 | RegisterMessenger(new G4VisCommandViewerZoom); |
---|
1127 | |
---|
1128 | directory = new G4UIdirectory ("/vis/viewer/set/"); |
---|
1129 | directory -> SetGuidance ("Set view parameters of current viewer."); |
---|
1130 | fDirectoryList.push_back (directory); |
---|
1131 | RegisterMessenger(new G4VisCommandsViewerSet); |
---|
1132 | |
---|
1133 | // List manager commands |
---|
1134 | RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> > |
---|
1135 | (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement())); |
---|
1136 | RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> > |
---|
1137 | (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement())); |
---|
1138 | |
---|
1139 | // Trajectory filter manager commands |
---|
1140 | RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> > |
---|
1141 | (fpTrajFilterMgr, fpTrajFilterMgr->Placement())); |
---|
1142 | RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> > |
---|
1143 | (fpTrajFilterMgr, fpTrajFilterMgr->Placement())); |
---|
1144 | |
---|
1145 | // Hit filter manager commands |
---|
1146 | RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> > |
---|
1147 | (fpHitFilterMgr, fpHitFilterMgr->Placement())); |
---|
1148 | RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> > |
---|
1149 | (fpHitFilterMgr, fpHitFilterMgr->Placement())); |
---|
1150 | } |
---|
1151 | |
---|
1152 | void G4VisManager::PrintAvailableGraphicsSystems () const { |
---|
1153 | G4int nSystems = fAvailableGraphicsSystems.size (); |
---|
1154 | G4cout << "Current available graphics systems are:"; |
---|
1155 | if (nSystems) { |
---|
1156 | for (int i = 0; i < nSystems; i++) { |
---|
1157 | const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems [i]; |
---|
1158 | G4cout << "\n " << pSystem -> GetName (); |
---|
1159 | if (pSystem -> GetNickname () != "") { |
---|
1160 | G4cout << " (" << pSystem -> GetNickname () << ")"; |
---|
1161 | } |
---|
1162 | } |
---|
1163 | } |
---|
1164 | else { |
---|
1165 | G4cout << "\n NONE!!! None registered - yet! Mmmmm!"; |
---|
1166 | } |
---|
1167 | G4cout << G4endl; |
---|
1168 | } |
---|
1169 | |
---|
1170 | void G4VisManager::PrintAvailableModels (Verbosity verbosity) const |
---|
1171 | { |
---|
1172 | { |
---|
1173 | //fpTrajDrawModelMgr->Print(G4cout); |
---|
1174 | G4cout << "Registered model factories:" << G4endl; |
---|
1175 | const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList = |
---|
1176 | fpTrajDrawModelMgr->FactoryList(); |
---|
1177 | if (factoryList.empty()) G4cout << " None" << G4endl; |
---|
1178 | else { |
---|
1179 | std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i; |
---|
1180 | for (i = factoryList.begin(); i != factoryList.end(); ++i) |
---|
1181 | (*i)->Print(G4cout); |
---|
1182 | } |
---|
1183 | const G4VisListManager<G4VTrajectoryModel>* listManager = |
---|
1184 | fpTrajDrawModelMgr->ListManager(); |
---|
1185 | const std::map<G4String, G4VTrajectoryModel*>& modelMap = |
---|
1186 | listManager->Map(); |
---|
1187 | if (!modelMap.empty()) { |
---|
1188 | G4cout << "\nRegistered models:" << G4endl; |
---|
1189 | std::map<G4String, G4VTrajectoryModel*>::const_iterator i; |
---|
1190 | for (i = modelMap.begin(); i != modelMap.end(); ++i) { |
---|
1191 | G4cout << " " << i->second->Name(); |
---|
1192 | if (i->second == listManager->Current()) G4cout << " (Current)"; |
---|
1193 | G4cout << G4endl; |
---|
1194 | if (verbosity >= parameters) i->second->Print(G4cout); |
---|
1195 | } |
---|
1196 | } |
---|
1197 | } |
---|
1198 | |
---|
1199 | G4cout << G4endl; |
---|
1200 | |
---|
1201 | { |
---|
1202 | //fpTrajFilterMgr->Print(G4cout); |
---|
1203 | G4cout << "Registered filter factories:" << G4endl; |
---|
1204 | const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>& |
---|
1205 | factoryList = fpTrajFilterMgr->FactoryList(); |
---|
1206 | if (factoryList.empty()) G4cout << " None" << G4endl; |
---|
1207 | else { |
---|
1208 | std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i; |
---|
1209 | for (i = factoryList.begin(); i != factoryList.end(); ++i) |
---|
1210 | (*i)->Print(G4cout); |
---|
1211 | } |
---|
1212 | const std::vector<G4VFilter<G4VTrajectory>*>& |
---|
1213 | filterList = fpTrajFilterMgr->FilterList(); |
---|
1214 | if (!filterList.empty()) { |
---|
1215 | G4cout << "\nRegistered filters:" << G4endl; |
---|
1216 | std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i; |
---|
1217 | for (i = filterList.begin(); i != filterList.end(); ++i) { |
---|
1218 | G4cout << " " << (*i)->GetName() << G4endl; |
---|
1219 | if (verbosity >= parameters) (*i)->PrintAll(G4cout); |
---|
1220 | } |
---|
1221 | } |
---|
1222 | } |
---|
1223 | } |
---|
1224 | |
---|
1225 | void G4VisManager::PrintInvalidPointers () const { |
---|
1226 | if (fVerbosity >= errors) { |
---|
1227 | G4cout << "ERROR: G4VisManager::PrintInvalidPointers:"; |
---|
1228 | if (!fpGraphicsSystem) { |
---|
1229 | G4cout << "\n null graphics system pointer."; |
---|
1230 | } |
---|
1231 | else { |
---|
1232 | G4cout << "\n Graphics system is " << fpGraphicsSystem -> GetName () |
---|
1233 | << " but:"; |
---|
1234 | if (!fpScene) |
---|
1235 | G4cout << |
---|
1236 | "\n Null scene pointer. Use \"/vis/drawVolume\" or" |
---|
1237 | " \"/vis/scene/create\"."; |
---|
1238 | if (!fpSceneHandler) |
---|
1239 | G4cout << |
---|
1240 | "\n Null scene handler pointer. Use \"/vis/open\" or" |
---|
1241 | " \"/vis/sceneHandler/create\"."; |
---|
1242 | if (!fpViewer ) |
---|
1243 | G4cout << |
---|
1244 | "\n Null viewer pointer. Use \"/vis/viewer/create\"."; |
---|
1245 | } |
---|
1246 | G4cout << G4endl; |
---|
1247 | } |
---|
1248 | } |
---|
1249 | |
---|
1250 | void G4VisManager::BeginOfRun () |
---|
1251 | { |
---|
1252 | //G4cout << "G4VisManager::BeginOfRun" << G4endl; |
---|
1253 | fKeptLastEvent = false; |
---|
1254 | fEventKeepingSuspended = false; |
---|
1255 | fTransientsDrawnThisRun = false; |
---|
1256 | if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false); |
---|
1257 | } |
---|
1258 | |
---|
1259 | void G4VisManager::BeginOfEvent () |
---|
1260 | { |
---|
1261 | //G4cout << "G4VisManager::BeginOfEvent" << G4endl; |
---|
1262 | fTransientsDrawnThisEvent = false; |
---|
1263 | if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false); |
---|
1264 | } |
---|
1265 | |
---|
1266 | void G4VisManager::EndOfEvent () |
---|
1267 | { |
---|
1268 | printf("G4VisManager::EndOfEvent \n"); |
---|
1269 | |
---|
1270 | //G4cout << "G4VisManager::EndOfEvent" << G4endl; |
---|
1271 | |
---|
1272 | // Don't call IsValidView unless there is a scene handler. This |
---|
1273 | // avoids WARNING message at end of event and run when the user has |
---|
1274 | // not instantiated a scene handler, e.g., in batch mode. |
---|
1275 | G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView(); |
---|
1276 | if (!valid) return; |
---|
1277 | |
---|
1278 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
1279 | const G4Run* currentRun = runManager->GetCurrentRun(); |
---|
1280 | |
---|
1281 | G4EventManager* eventManager = G4EventManager::GetEventManager(); |
---|
1282 | const G4Event* currentEvent = eventManager->GetConstCurrentEvent(); |
---|
1283 | if (!currentEvent) return; |
---|
1284 | |
---|
1285 | // FIXME : OK |
---|
1286 | printf("G4VisManager::EndOfEvent 0\n"); |
---|
1287 | ClearTransientStoreIfMarked(); |
---|
1288 | printf("G4VisManager::EndOfEvent 1\n"); |
---|
1289 | // FIXME : OK |
---|
1290 | fpSceneHandler->DrawEvent(currentEvent); |
---|
1291 | |
---|
1292 | G4int nEventsToBeProcessed = 0; |
---|
1293 | G4int nKeptEvents = 0; |
---|
1294 | G4int eventID = -2; // (If no run manager, triggers ShowView as normal.) |
---|
1295 | printf("G4VisManager::EndOfEvent 2\n"); |
---|
1296 | if (currentRun) { |
---|
1297 | printf("G4VisManager::EndOfEvent currentRun?\n"); |
---|
1298 | nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed(); |
---|
1299 | eventID = currentEvent->GetEventID(); |
---|
1300 | const std::vector<const G4Event*>* events = |
---|
1301 | currentRun->GetEventVector(); |
---|
1302 | if (events) nKeptEvents = events->size(); |
---|
1303 | } |
---|
1304 | |
---|
1305 | if (fpScene->GetRefreshAtEndOfEvent()) { |
---|
1306 | printf("G4VisManager::EndOfEvent GetRefreshAtEndOfEvent()\n"); |
---|
1307 | |
---|
1308 | // Unless last event (in which case wait end of run)... |
---|
1309 | if (eventID < nEventsToBeProcessed - 1) { |
---|
1310 | printf("G4VisManager::EndOfEvent 3 \n"); |
---|
1311 | fpViewer->ShowView(); |
---|
1312 | fpSceneHandler->SetMarkForClearingTransientStore(true); |
---|
1313 | } else { // Last event... |
---|
1314 | printf("G4VisManager::EndOfEvent 4 \n"); |
---|
1315 | // Keep, but only if user has not kept any... |
---|
1316 | if (!nKeptEvents) { |
---|
1317 | eventManager->KeepTheCurrentEvent(); |
---|
1318 | fKeptLastEvent = true; |
---|
1319 | } |
---|
1320 | } |
---|
1321 | |
---|
1322 | } else { // Accumulating events... |
---|
1323 | printf("G4VisManager::EndOfEvent NOT GetRefreshAtEndOfEvent()\n"); |
---|
1324 | |
---|
1325 | G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents(); |
---|
1326 | if (maxNumberOfKeptEvents > 0 && nKeptEvents >= maxNumberOfKeptEvents) { |
---|
1327 | printf("G4VisManager::EndOfEvent 5 \n"); |
---|
1328 | fEventKeepingSuspended = true; |
---|
1329 | static G4bool warned = false; |
---|
1330 | if (!warned) { |
---|
1331 | printf("G4VisManager::EndOfEvent 6 \n"); |
---|
1332 | if (fVerbosity >= warnings) { |
---|
1333 | printf("G4VisManager::EndOfEvent 7 \n"); |
---|
1334 | G4cout << |
---|
1335 | "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended." |
---|
1336 | "\n The number of events exceeds the maximum, " |
---|
1337 | << maxNumberOfKeptEvents << |
---|
1338 | ", that can be kept by the vis manager." |
---|
1339 | << G4endl; |
---|
1340 | } |
---|
1341 | warned = true; |
---|
1342 | } |
---|
1343 | } else if (maxNumberOfKeptEvents != 0) { |
---|
1344 | printf("G4VisManager::EndOfEvent 8 \n"); |
---|
1345 | eventManager->KeepTheCurrentEvent(); |
---|
1346 | } |
---|
1347 | } |
---|
1348 | printf("G4VisManager::EndOfEvent 9 \n"); |
---|
1349 | } |
---|
1350 | |
---|
1351 | void G4VisManager::EndOfRun () |
---|
1352 | { |
---|
1353 | //G4cout << "G4VisManager::EndOfRun" << G4endl; |
---|
1354 | printf("G4VisManager::EndOfRun 1\n"); |
---|
1355 | // Don't call IsValidView unless there is a scene handler. This |
---|
1356 | // avoids WARNING message at end of event and run when the user has |
---|
1357 | // not instantiated a scene handler, e.g., in batch mode. |
---|
1358 | G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView(); |
---|
1359 | printf("G4VisManager::EndOfRun 2\n"); |
---|
1360 | if (valid) { |
---|
1361 | printf("G4VisManager::EndOfRun 3\n"); |
---|
1362 | if (!fpSceneHandler->GetMarkForClearingTransientStore()) { |
---|
1363 | printf("G4VisManager::EndOfRun 4\n"); |
---|
1364 | if (fpScene->GetRefreshAtEndOfRun()) { |
---|
1365 | printf("G4VisManager::EndOfRun 5\n"); |
---|
1366 | fpViewer->ShowView(); |
---|
1367 | printf("G4VisManager::EndOfRun 6\n"); |
---|
1368 | fpSceneHandler->SetMarkForClearingTransientStore(true); |
---|
1369 | printf("G4VisManager::EndOfRun 7\n"); |
---|
1370 | } |
---|
1371 | } |
---|
1372 | |
---|
1373 | printf("G4VisManager::EndOfRun 8\n"); |
---|
1374 | if (fEventKeepingSuspended && fVerbosity >= warnings) { |
---|
1375 | G4cout << |
---|
1376 | "WARNING: G4VisManager::EndOfRun: Automatic event keeping has been suspended." |
---|
1377 | "\n The number of events in the run exceeded the maximum, " |
---|
1378 | << fpScene->GetMaxNumberOfKeptEvents() << |
---|
1379 | ", that can be kept by the vis manager." << |
---|
1380 | "\n The number of events kept by the vis manager can be changed with" |
---|
1381 | "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the" |
---|
1382 | "\n maximum number you wish to allow. N < 0 means \"unlimited\"." |
---|
1383 | << G4endl; |
---|
1384 | } |
---|
1385 | } |
---|
1386 | fEventRefreshing = false; |
---|
1387 | |
---|
1388 | printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); |
---|
1389 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
1390 | const G4Run* currentRun = runManager->GetCurrentRun(); |
---|
1391 | |
---|
1392 | G4int nKeptEvents = 0; |
---|
1393 | const std::vector<const G4Event*>* events = |
---|
1394 | currentRun? currentRun->GetEventVector(): 0; |
---|
1395 | if (events) nKeptEvents = events->size(); |
---|
1396 | |
---|
1397 | if (nKeptEvents && !fKeptLastEvent) { |
---|
1398 | if (!valid && fVerbosity >= warnings) G4cout << "WARNING: "; |
---|
1399 | if (fVerbosity >= warnings) { |
---|
1400 | G4cout << nKeptEvents; |
---|
1401 | if (nKeptEvents == 1) G4cout << " event has"; |
---|
1402 | else G4cout << " events have"; |
---|
1403 | G4cout << " been kept for refreshing and/or reviewing." << G4endl; |
---|
1404 | } |
---|
1405 | static G4bool warned = false; |
---|
1406 | if (!valid && fVerbosity >= warnings && !warned) { |
---|
1407 | G4cout << |
---|
1408 | " Only useful if before starting the run:" |
---|
1409 | "\n a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or" |
---|
1410 | "\n b) the Draw method of any hits is implemented." |
---|
1411 | "\n To view trajectories and hits:" |
---|
1412 | "\n open a viewer, draw a volume, \"/vis/scene/add/trajectories\"" |
---|
1413 | "\n \"/vis/scene/add/hits\" and, possibly, \"/vis/viewer/flush\"." |
---|
1414 | "\n To see all events: \"/vis/scene/endOfEventAction accumulate\"." |
---|
1415 | "\n To see events individually: \"/vis/reviewKeptEvents\"." |
---|
1416 | << G4endl; |
---|
1417 | warned = true; |
---|
1418 | } |
---|
1419 | } |
---|
1420 | } |
---|
1421 | |
---|
1422 | void G4VisManager::ClearTransientStoreIfMarked(){ |
---|
1423 | // Assumes valid view. |
---|
1424 | if (fpSceneHandler->GetMarkForClearingTransientStore()) { |
---|
1425 | fpSceneHandler->SetMarkForClearingTransientStore(false); |
---|
1426 | fpSceneHandler->ClearTransientStore(); |
---|
1427 | } |
---|
1428 | // Record if transients drawn. These local flags are only set |
---|
1429 | // *after* ClearTransientStore. In the code in G4VSceneHandler |
---|
1430 | // triggered by ClearTransientStore, use these flags so that |
---|
1431 | // event refreshing is not done too early. |
---|
1432 | fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent(); |
---|
1433 | fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun(); |
---|
1434 | } |
---|
1435 | |
---|
1436 | void G4VisManager::ResetTransientsDrawnFlags() |
---|
1437 | { |
---|
1438 | fTransientsDrawnThisRun = false; |
---|
1439 | fTransientsDrawnThisEvent = false; |
---|
1440 | G4SceneHandlerListConstIterator i; |
---|
1441 | for (i = fAvailableSceneHandlers.begin(); |
---|
1442 | i != fAvailableSceneHandlers.end(); ++i) { |
---|
1443 | (*i)->SetTransientsDrawnThisEvent(false); |
---|
1444 | (*i)->SetTransientsDrawnThisRun(false); |
---|
1445 | } |
---|
1446 | } |
---|
1447 | |
---|
1448 | G4String G4VisManager::ViewerShortName (const G4String& viewerName) const { |
---|
1449 | G4String viewerShortName (viewerName); |
---|
1450 | viewerShortName = viewerShortName (0, viewerShortName.find (' ')); |
---|
1451 | return viewerShortName.strip (); |
---|
1452 | } |
---|
1453 | |
---|
1454 | G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const { |
---|
1455 | G4String viewerShortName = ViewerShortName (viewerName); |
---|
1456 | size_t nHandlers = fAvailableSceneHandlers.size (); |
---|
1457 | size_t iHandler, iViewer; |
---|
1458 | G4VViewer* viewer = 0; |
---|
1459 | G4bool found = false; |
---|
1460 | for (iHandler = 0; iHandler < nHandlers; iHandler++) { |
---|
1461 | G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler]; |
---|
1462 | const G4ViewerList& viewerList = sceneHandler -> GetViewerList (); |
---|
1463 | for (iViewer = 0; iViewer < viewerList.size (); iViewer++) { |
---|
1464 | viewer = viewerList [iViewer]; |
---|
1465 | if (viewerShortName == viewer -> GetShortName ()) { |
---|
1466 | found = true; |
---|
1467 | break; |
---|
1468 | } |
---|
1469 | } |
---|
1470 | if (found) break; |
---|
1471 | } |
---|
1472 | if (found) return viewer; |
---|
1473 | else return 0; |
---|
1474 | } |
---|
1475 | |
---|
1476 | std::vector<G4String> G4VisManager::VerbosityGuidanceStrings; |
---|
1477 | |
---|
1478 | G4String G4VisManager::VerbosityString(Verbosity verbosity) { |
---|
1479 | G4String s; |
---|
1480 | switch (verbosity) { |
---|
1481 | case quiet: s = "quiet (0)"; break; |
---|
1482 | case startup: s = "startup (1)"; break; |
---|
1483 | case errors: s = "errors (2)"; break; |
---|
1484 | case warnings: s = "warnings (3)"; break; |
---|
1485 | case confirmations: s = "confirmations (4)"; break; |
---|
1486 | case parameters: s = "parameters (5)"; break; |
---|
1487 | case all: s = "all (6)"; break; |
---|
1488 | } |
---|
1489 | return s; |
---|
1490 | } |
---|
1491 | |
---|
1492 | G4VisManager::Verbosity |
---|
1493 | G4VisManager::GetVerbosityValue(const G4String& verbosityString) { |
---|
1494 | G4String s(verbosityString); s.toLower(); |
---|
1495 | Verbosity verbosity; |
---|
1496 | if (s(0) == 'q') verbosity = quiet; |
---|
1497 | else if (s(0) == 's') verbosity = startup; |
---|
1498 | else if (s(0) == 'e') verbosity = errors; |
---|
1499 | else if (s(0) == 'w') verbosity = warnings; |
---|
1500 | else if (s(0) == 'c') verbosity = confirmations; |
---|
1501 | else if (s(0) == 'p') verbosity = parameters; |
---|
1502 | else if (s(0) == 'a') verbosity = all; |
---|
1503 | else { |
---|
1504 | G4int intVerbosity; |
---|
1505 | std::istringstream is(s); |
---|
1506 | is >> intVerbosity; |
---|
1507 | if (!is) { |
---|
1508 | G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \"" |
---|
1509 | << verbosityString << "\""; |
---|
1510 | for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) { |
---|
1511 | G4cout << '\n' << VerbosityGuidanceStrings[i]; |
---|
1512 | } |
---|
1513 | verbosity = warnings; |
---|
1514 | G4cout << "\n Returning " << VerbosityString(verbosity) |
---|
1515 | << G4endl; |
---|
1516 | } |
---|
1517 | else { |
---|
1518 | verbosity = GetVerbosityValue(intVerbosity); |
---|
1519 | } |
---|
1520 | } |
---|
1521 | return verbosity; |
---|
1522 | } |
---|
1523 | |
---|
1524 | G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) { |
---|
1525 | Verbosity verbosity; |
---|
1526 | if (intVerbosity < quiet) verbosity = quiet; |
---|
1527 | else if (intVerbosity > all) verbosity = all; |
---|
1528 | else verbosity = Verbosity(intVerbosity); |
---|
1529 | return verbosity; |
---|
1530 | } |
---|
1531 | |
---|
1532 | void G4VisManager::SetVerboseLevel (G4int intVerbosity) { |
---|
1533 | fVerbosity = GetVerbosityValue(intVerbosity); |
---|
1534 | } |
---|
1535 | |
---|
1536 | void G4VisManager::SetVerboseLevel (const G4String& verbosityString) { |
---|
1537 | fVerbosity = GetVerbosityValue(verbosityString); |
---|
1538 | } |
---|
1539 | |
---|
1540 | G4bool G4VisManager::IsValidView () { |
---|
1541 | |
---|
1542 | if (!fInitialised) Initialise (); |
---|
1543 | |
---|
1544 | static G4bool noGSPrinting = true; |
---|
1545 | if (!fpGraphicsSystem) { |
---|
1546 | // Limit printing - we do not want printing if the user simply does |
---|
1547 | // not want to use graphics, e.g., in batch mode. |
---|
1548 | if (noGSPrinting) { |
---|
1549 | noGSPrinting = false; |
---|
1550 | if (fVerbosity >= warnings) { |
---|
1551 | G4cout << |
---|
1552 | "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system" |
---|
1553 | "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"." |
---|
1554 | "\n Alternatively, to avoid this message, suppress instantiation of vis" |
---|
1555 | "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure" |
---|
1556 | "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()" |
---|
1557 | "\n is non-zero." |
---|
1558 | << G4endl; |
---|
1559 | } |
---|
1560 | } |
---|
1561 | return false; |
---|
1562 | } |
---|
1563 | |
---|
1564 | if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) { |
---|
1565 | if (fVerbosity >= errors) { |
---|
1566 | G4cout << |
---|
1567 | "ERROR: G4VisManager::IsValidView(): Current view is not valid." |
---|
1568 | << G4endl; |
---|
1569 | PrintInvalidPointers (); |
---|
1570 | } |
---|
1571 | return false; |
---|
1572 | } |
---|
1573 | |
---|
1574 | if (fpScene != fpSceneHandler -> GetScene ()) { |
---|
1575 | if (fVerbosity >= errors) { |
---|
1576 | G4cout << "ERROR: G4VisManager::IsValidView ():"; |
---|
1577 | if (fpSceneHandler -> GetScene ()) { |
---|
1578 | G4cout << |
---|
1579 | "\n The current scene \"" |
---|
1580 | << fpScene -> GetName () |
---|
1581 | << "\" is not handled by" |
---|
1582 | "\n the current scene handler \"" |
---|
1583 | << fpSceneHandler -> GetName () |
---|
1584 | << "\"" |
---|
1585 | "\n (it currently handles scene \"" |
---|
1586 | << fpSceneHandler -> GetScene () -> GetName () |
---|
1587 | << "\")." |
---|
1588 | "\n Either:" |
---|
1589 | "\n (a) attach it to the scene handler with" |
---|
1590 | "\n /vis/sceneHandler/attach " |
---|
1591 | << fpScene -> GetName () |
---|
1592 | << ", or" |
---|
1593 | "\n (b) create a new scene handler with " |
---|
1594 | "\n /vis/sceneHandler/create <graphics-system>," |
---|
1595 | "\n in which case it should pick up the the new scene." |
---|
1596 | << G4endl; |
---|
1597 | } |
---|
1598 | else { |
---|
1599 | G4cout << "\n Scene handler \"" |
---|
1600 | << fpSceneHandler -> GetName () |
---|
1601 | << "\" has null scene pointer." |
---|
1602 | "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]" |
---|
1603 | << G4endl; |
---|
1604 | } |
---|
1605 | } |
---|
1606 | return false; |
---|
1607 | } |
---|
1608 | |
---|
1609 | const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList (); |
---|
1610 | if (viewerList.size () == 0) { |
---|
1611 | if (fVerbosity >= errors) { |
---|
1612 | G4cout << |
---|
1613 | "ERROR: G4VisManager::IsValidView (): the current scene handler\n \"" |
---|
1614 | << fpSceneHandler -> GetName () |
---|
1615 | << "\" has no viewers. Do /vis/viewer/create." |
---|
1616 | << G4endl; |
---|
1617 | } |
---|
1618 | return false; |
---|
1619 | } |
---|
1620 | |
---|
1621 | G4bool isValid = true; |
---|
1622 | if (fpScene -> IsEmpty ()) { // Add world by default if possible... |
---|
1623 | G4bool warn(fVerbosity >= warnings); |
---|
1624 | G4bool successful = fpScene -> AddWorldIfEmpty (warn); |
---|
1625 | if (!successful || fpScene -> IsEmpty ()) { // If still empty... |
---|
1626 | if (fVerbosity >= errors) { |
---|
1627 | G4cout << "ERROR: G4VisManager::IsViewValid ():"; |
---|
1628 | G4cout << |
---|
1629 | "\n Attempt at some drawing operation when scene is empty." |
---|
1630 | "\n Maybe the geometry has not yet been defined." |
---|
1631 | " Try /run/initialize." |
---|
1632 | << G4endl; |
---|
1633 | } |
---|
1634 | isValid = false; |
---|
1635 | } |
---|
1636 | else { |
---|
1637 | G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers"); |
---|
1638 | if (fVerbosity >= warnings) { |
---|
1639 | G4cout << |
---|
1640 | "WARNING: G4VisManager: the scene was empty, \"world\" has been" |
---|
1641 | "\n added and the scene handlers notified."; |
---|
1642 | G4cout << G4endl; |
---|
1643 | } |
---|
1644 | } |
---|
1645 | } |
---|
1646 | if (isValid) SetConcreteInstance(this); |
---|
1647 | return isValid; |
---|
1648 | } |
---|
1649 | |
---|
1650 | void |
---|
1651 | G4VisManager::RegisterModelFactories() |
---|
1652 | { |
---|
1653 | if (fVerbosity >= warnings) { |
---|
1654 | G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl; |
---|
1655 | G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl; |
---|
1656 | G4cout<<"class. See G4VisExecutive for an example."<<G4endl; |
---|
1657 | } |
---|
1658 | } |
---|