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 | // $Id: G4VisCommandsScene.cc,v 1.66 2007/05/25 10:49:55 allison Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-00-ref-01 $ |
---|
29 | |
---|
30 | // /vis/scene commands - John Allison 9th August 1998 |
---|
31 | |
---|
32 | #include "G4VisCommandsScene.hh" |
---|
33 | |
---|
34 | #include "G4VisManager.hh" |
---|
35 | #include "G4TransportationManager.hh" |
---|
36 | #include "G4PhysicalVolumeModel.hh" |
---|
37 | #include "G4ApplicationState.hh" |
---|
38 | #include "G4UImanager.hh" |
---|
39 | #include "G4UIcommand.hh" |
---|
40 | #include "G4UIcmdWithAString.hh" |
---|
41 | #include "G4ios.hh" |
---|
42 | #include <sstream> |
---|
43 | |
---|
44 | G4VVisCommandScene::G4VVisCommandScene () {} |
---|
45 | |
---|
46 | G4VVisCommandScene::~G4VVisCommandScene () {} |
---|
47 | |
---|
48 | G4String G4VVisCommandScene::CurrentSceneName () { |
---|
49 | const G4Scene* pScene = fpVisManager -> GetCurrentScene (); |
---|
50 | G4String currentSceneName; |
---|
51 | if (pScene) currentSceneName = pScene -> GetName (); |
---|
52 | return currentSceneName; |
---|
53 | } |
---|
54 | |
---|
55 | ////////////// /vis/scene/create /////////////////////////////////////// |
---|
56 | |
---|
57 | G4VisCommandSceneCreate::G4VisCommandSceneCreate (): fId (0) { |
---|
58 | G4bool omitable; |
---|
59 | fpCommand = new G4UIcmdWithAString ("/vis/scene/create", this); |
---|
60 | fpCommand -> SetGuidance |
---|
61 | ("Creates an empty scene."); |
---|
62 | fpCommand -> SetGuidance |
---|
63 | ("Invents a name if not supplied. This scene becomes current."); |
---|
64 | fpCommand -> SetParameterName ("scene-name", omitable = true); |
---|
65 | } |
---|
66 | |
---|
67 | G4VisCommandSceneCreate::~G4VisCommandSceneCreate () { |
---|
68 | delete fpCommand; |
---|
69 | } |
---|
70 | |
---|
71 | G4String G4VisCommandSceneCreate::NextName () { |
---|
72 | std::ostringstream oss; |
---|
73 | oss << "scene-" << fId; |
---|
74 | return oss.str(); |
---|
75 | } |
---|
76 | |
---|
77 | G4String G4VisCommandSceneCreate::GetCurrentValue (G4UIcommand*) { |
---|
78 | return ""; |
---|
79 | } |
---|
80 | |
---|
81 | void G4VisCommandSceneCreate::SetNewValue (G4UIcommand*, G4String newValue) { |
---|
82 | |
---|
83 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
84 | |
---|
85 | G4String& newName = newValue; |
---|
86 | G4String nextName = NextName (); |
---|
87 | |
---|
88 | if (newName == "") { |
---|
89 | newName = nextName; |
---|
90 | } |
---|
91 | if (newName == nextName) fId++; |
---|
92 | |
---|
93 | G4SceneList& sceneList = fpVisManager -> SetSceneList (); |
---|
94 | G4int iScene, nScenes = sceneList.size (); |
---|
95 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
96 | if (sceneList [iScene] -> GetName () == newName) break; |
---|
97 | } |
---|
98 | if (iScene < nScenes) { |
---|
99 | if (verbosity >= G4VisManager::warnings) { |
---|
100 | G4cout << "WARNING: Scene \"" << newName << "\" already exists." |
---|
101 | << "\n New scene not created." |
---|
102 | << G4endl; |
---|
103 | } |
---|
104 | } else { |
---|
105 | |
---|
106 | // Add empty scene data object to list... |
---|
107 | G4Scene* pScene = new G4Scene (newName); |
---|
108 | sceneList.push_back (pScene); |
---|
109 | fpVisManager -> SetCurrentScene (pScene); |
---|
110 | |
---|
111 | if (verbosity >= G4VisManager::confirmations) { |
---|
112 | G4cout << "New empty scene \"" << newName << "\" created." << G4endl; |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | ////////////// /vis/scene/endOfEventAction //////////////////////////// |
---|
118 | |
---|
119 | G4VisCommandSceneEndOfEventAction::G4VisCommandSceneEndOfEventAction () { |
---|
120 | G4bool omitable; |
---|
121 | fpCommand = new G4UIcommand ("/vis/scene/endOfEventAction", this); |
---|
122 | fpCommand -> SetGuidance |
---|
123 | ("Accumulate or refresh the viewer for each new event."); |
---|
124 | fpCommand -> SetGuidance |
---|
125 | ("\"accumulate\": viewer accumulates hits, etc., event by event, or"); |
---|
126 | fpCommand -> SetGuidance |
---|
127 | ("\"refresh\": viewer shows them at end of event or, for direct-screen" |
---|
128 | "\n viewers, refreshes the screen just before drawing the next event."); |
---|
129 | G4UIparameter* parameter; |
---|
130 | parameter = new G4UIparameter ("action", 's', omitable = true); |
---|
131 | parameter -> SetParameterCandidates ("accumulate refresh"); |
---|
132 | parameter -> SetDefaultValue ("refresh"); |
---|
133 | fpCommand -> SetParameter (parameter); |
---|
134 | parameter = new G4UIparameter ("maxNumber", 'i', omitable = true); |
---|
135 | parameter -> SetDefaultValue (100); |
---|
136 | parameter -> SetGuidance |
---|
137 | ("Maximum number of events kept. Unlimited if negative."); |
---|
138 | fpCommand -> SetParameter (parameter); |
---|
139 | } |
---|
140 | |
---|
141 | G4VisCommandSceneEndOfEventAction::~G4VisCommandSceneEndOfEventAction () { |
---|
142 | delete fpCommand; |
---|
143 | } |
---|
144 | |
---|
145 | G4String G4VisCommandSceneEndOfEventAction::GetCurrentValue(G4UIcommand*) { |
---|
146 | return ""; |
---|
147 | } |
---|
148 | |
---|
149 | void G4VisCommandSceneEndOfEventAction::SetNewValue (G4UIcommand*, |
---|
150 | G4String newValue) { |
---|
151 | |
---|
152 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
153 | |
---|
154 | G4String action; |
---|
155 | G4int maxNumberOfKeptEvents; |
---|
156 | std::istringstream is (newValue); |
---|
157 | is >> action >> maxNumberOfKeptEvents; |
---|
158 | |
---|
159 | G4Scene* pScene = fpVisManager->GetCurrentScene(); |
---|
160 | if (!pScene) { |
---|
161 | if (verbosity >= G4VisManager::errors) { |
---|
162 | G4cout << "ERROR: No current scene. Please create one." << G4endl; |
---|
163 | } |
---|
164 | return; |
---|
165 | } |
---|
166 | |
---|
167 | G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler(); |
---|
168 | if (!pSceneHandler) { |
---|
169 | if (verbosity >= G4VisManager::errors) { |
---|
170 | G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl; |
---|
171 | } |
---|
172 | return; |
---|
173 | } |
---|
174 | |
---|
175 | if (action == "accumulate") { |
---|
176 | pScene->SetRefreshAtEndOfEvent(false); |
---|
177 | pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents); |
---|
178 | } |
---|
179 | else if (action == "refresh") { |
---|
180 | if (!pScene->GetRefreshAtEndOfRun()) { |
---|
181 | if (verbosity >= G4VisManager::errors) { |
---|
182 | G4cout << |
---|
183 | "ERROR: Cannot refresh events unless runs refresh too." |
---|
184 | "\n Use \"/vis/scene/endOfRun refresh\"." |
---|
185 | << G4endl; |
---|
186 | } |
---|
187 | } else { |
---|
188 | pScene->SetRefreshAtEndOfEvent(true); |
---|
189 | pSceneHandler->SetMarkForClearingTransientStore(true); |
---|
190 | } |
---|
191 | } |
---|
192 | else { |
---|
193 | if (verbosity >= G4VisManager::errors) { |
---|
194 | G4cout << |
---|
195 | "ERROR: unrecognised parameter \"" << action << "\"." |
---|
196 | << G4endl; |
---|
197 | } |
---|
198 | return; |
---|
199 | } |
---|
200 | |
---|
201 | // Change of transients behaviour, so... |
---|
202 | fpVisManager->ResetTransientsDrawnFlags(); |
---|
203 | |
---|
204 | if (verbosity >= G4VisManager::confirmations) { |
---|
205 | G4cout << "End of event action set to "; |
---|
206 | if (pScene->GetRefreshAtEndOfEvent()) G4cout << "\"refresh\"."; |
---|
207 | else { |
---|
208 | G4cout << "\"accumulate\"." |
---|
209 | "\n Maximum number of events to be kept: " |
---|
210 | << maxNumberOfKeptEvents |
---|
211 | << " (unlimited if negative)." |
---|
212 | "\n This may be changed with, e.g., " |
---|
213 | "\"/vis/scene/endOfEventAction accumulate 100\"." |
---|
214 | << G4endl; |
---|
215 | } |
---|
216 | } |
---|
217 | if (!pScene->GetRefreshAtEndOfEvent() && |
---|
218 | maxNumberOfKeptEvents != 0 && |
---|
219 | verbosity >= G4VisManager::warnings) { |
---|
220 | G4cout << "WARNING: The vis manager will keep "; |
---|
221 | if (maxNumberOfKeptEvents < 0) G4cout << "an unlimited number of"; |
---|
222 | else G4cout << "up to " << maxNumberOfKeptEvents; |
---|
223 | G4cout << " events."; |
---|
224 | if (maxNumberOfKeptEvents > 1 || maxNumberOfKeptEvents < 0) |
---|
225 | G4cout << "\n This may use a lot of memory."; |
---|
226 | G4cout << G4endl; |
---|
227 | } |
---|
228 | UpdateVisManagerScene (pScene->GetName()); |
---|
229 | } |
---|
230 | |
---|
231 | ////////////// /vis/scene/endOfRunAction //////////////////////////// |
---|
232 | |
---|
233 | G4VisCommandSceneEndOfRunAction::G4VisCommandSceneEndOfRunAction () { |
---|
234 | G4bool omitable; |
---|
235 | fpCommand = new G4UIcmdWithAString ("/vis/scene/endOfRunAction", this); |
---|
236 | fpCommand -> SetGuidance |
---|
237 | ("Accumulate or refresh the viewer for each new run."); |
---|
238 | fpCommand -> SetGuidance |
---|
239 | ("\"accumulate\": viewer accumulates hits, etc., run by run, or"); |
---|
240 | fpCommand -> SetGuidance |
---|
241 | ("\"refresh\": viewer shows them at end of run or, for direct-screen" |
---|
242 | "\n viewers, refreshes the screen just before drawing the first" |
---|
243 | "\n event of the next run."); |
---|
244 | fpCommand -> SetGuidance ("The detector remains or is redrawn."); |
---|
245 | fpCommand -> SetParameterName ("action", omitable = true); |
---|
246 | fpCommand -> SetCandidates ("accumulate refresh"); |
---|
247 | fpCommand -> SetDefaultValue ("refresh"); |
---|
248 | } |
---|
249 | |
---|
250 | G4VisCommandSceneEndOfRunAction::~G4VisCommandSceneEndOfRunAction () { |
---|
251 | delete fpCommand; |
---|
252 | } |
---|
253 | |
---|
254 | G4String G4VisCommandSceneEndOfRunAction::GetCurrentValue(G4UIcommand*) { |
---|
255 | return ""; |
---|
256 | } |
---|
257 | |
---|
258 | void G4VisCommandSceneEndOfRunAction::SetNewValue (G4UIcommand*, |
---|
259 | G4String newValue) { |
---|
260 | |
---|
261 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
262 | |
---|
263 | G4String action; |
---|
264 | std::istringstream is (newValue); |
---|
265 | is >> action; |
---|
266 | |
---|
267 | G4Scene* pScene = fpVisManager->GetCurrentScene(); |
---|
268 | if (!pScene) { |
---|
269 | if (verbosity >= G4VisManager::errors) { |
---|
270 | G4cout << "ERROR: No current scene. Please create one." << G4endl; |
---|
271 | } |
---|
272 | return; |
---|
273 | } |
---|
274 | |
---|
275 | G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler(); |
---|
276 | if (!pSceneHandler) { |
---|
277 | if (verbosity >= G4VisManager::errors) { |
---|
278 | G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl; |
---|
279 | } |
---|
280 | return; |
---|
281 | } |
---|
282 | |
---|
283 | if (action == "accumulate") { |
---|
284 | if (pScene->GetRefreshAtEndOfEvent()) { |
---|
285 | if (verbosity >= G4VisManager::errors) { |
---|
286 | G4cout << |
---|
287 | "ERROR: Cannot accumulate runs unless events accumulate too." |
---|
288 | "\n Use \"/vis/scene/endOfEventAction accumulate\"." |
---|
289 | << G4endl; |
---|
290 | } |
---|
291 | } |
---|
292 | else { |
---|
293 | pScene->SetRefreshAtEndOfRun(false); |
---|
294 | } |
---|
295 | } |
---|
296 | else if (action == "refresh") { |
---|
297 | pScene->SetRefreshAtEndOfRun(true); |
---|
298 | pSceneHandler->SetMarkForClearingTransientStore(true); |
---|
299 | } |
---|
300 | else { |
---|
301 | if (verbosity >= G4VisManager::errors) { |
---|
302 | G4cout << |
---|
303 | "ERROR: unrecognised parameter \"" << action << "\"." |
---|
304 | << G4endl; |
---|
305 | } |
---|
306 | return; |
---|
307 | } |
---|
308 | |
---|
309 | // Change of transients behaviour, so... |
---|
310 | fpVisManager->ResetTransientsDrawnFlags(); |
---|
311 | |
---|
312 | if (verbosity >= G4VisManager::confirmations) { |
---|
313 | G4cout << "End of run action set to \""; |
---|
314 | if (pScene->GetRefreshAtEndOfRun()) G4cout << "refresh"; |
---|
315 | else G4cout << "accumulate"; |
---|
316 | G4cout << "\"" << G4endl; |
---|
317 | } |
---|
318 | UpdateVisManagerScene (pScene->GetName()); |
---|
319 | } |
---|
320 | |
---|
321 | ////////////// /vis/scene/list /////////////////////////////////////// |
---|
322 | |
---|
323 | G4VisCommandSceneList::G4VisCommandSceneList () { |
---|
324 | G4bool omitable; |
---|
325 | fpCommand = new G4UIcommand ("/vis/scene/list", this); |
---|
326 | fpCommand -> SetGuidance ("Lists scene(s)."); |
---|
327 | fpCommand -> SetGuidance |
---|
328 | ("\"help /vis/verbose\" for definition of verbosity."); |
---|
329 | G4UIparameter* parameter; |
---|
330 | parameter = new G4UIparameter ("scene-name", 's', omitable = true); |
---|
331 | parameter -> SetDefaultValue ("all"); |
---|
332 | fpCommand -> SetParameter (parameter); |
---|
333 | parameter = new G4UIparameter ("verbosity", 's', omitable = true); |
---|
334 | parameter -> SetDefaultValue ("warnings"); |
---|
335 | fpCommand -> SetParameter (parameter); |
---|
336 | } |
---|
337 | |
---|
338 | G4VisCommandSceneList::~G4VisCommandSceneList () { |
---|
339 | delete fpCommand; |
---|
340 | } |
---|
341 | |
---|
342 | G4String G4VisCommandSceneList::GetCurrentValue (G4UIcommand*) { |
---|
343 | return ""; |
---|
344 | } |
---|
345 | |
---|
346 | void G4VisCommandSceneList::SetNewValue (G4UIcommand*, G4String newValue) { |
---|
347 | G4String name, verbosityString; |
---|
348 | std::istringstream is (newValue); |
---|
349 | is >> name >> verbosityString; |
---|
350 | G4VisManager::Verbosity verbosity = |
---|
351 | fpVisManager->GetVerbosityValue(verbosityString); |
---|
352 | const G4Scene* currentScene = fpVisManager -> GetCurrentScene (); |
---|
353 | G4String currentName; |
---|
354 | if (currentScene) currentName = currentScene->GetName(); |
---|
355 | |
---|
356 | G4SceneList& sceneList = fpVisManager -> SetSceneList (); |
---|
357 | G4int iScene, nScenes = sceneList.size (); |
---|
358 | G4bool found = false; |
---|
359 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
360 | G4Scene* pScene = sceneList [iScene]; |
---|
361 | const G4String& iName = pScene -> GetName (); |
---|
362 | if (name != "all") { |
---|
363 | if (name != iName) continue; |
---|
364 | } |
---|
365 | found = true; |
---|
366 | if (iName == currentName) { |
---|
367 | G4cout << " (current)"; |
---|
368 | } |
---|
369 | else { |
---|
370 | G4cout << " "; |
---|
371 | } |
---|
372 | G4cout << " scene \"" << iName << "\""; |
---|
373 | if (verbosity >= G4VisManager::confirmations) { |
---|
374 | G4int i; |
---|
375 | G4cout << "\n Run-duration models:"; |
---|
376 | G4int nRunModels = pScene -> GetRunDurationModelList ().size (); |
---|
377 | if (nRunModels == 0) { |
---|
378 | G4cout << " none."; |
---|
379 | } |
---|
380 | for (i = 0; i < nRunModels; i++) { |
---|
381 | G4VModel* pModel = pScene -> GetRunDurationModelList () [i]; |
---|
382 | G4cout << "\n " << pModel -> GetGlobalDescription (); |
---|
383 | } |
---|
384 | G4cout << "\n End-of-event models:"; |
---|
385 | G4int nEOEModels = pScene -> GetEndOfEventModelList ().size (); |
---|
386 | if (nEOEModels == 0) { |
---|
387 | G4cout << " none."; |
---|
388 | } |
---|
389 | for (i = 0; i < nEOEModels; i++) { |
---|
390 | G4VModel* pModel = pScene -> GetEndOfEventModelList () [i]; |
---|
391 | G4cout << "\n " << pModel -> GetGlobalDescription (); |
---|
392 | } |
---|
393 | } |
---|
394 | if (verbosity >= G4VisManager::parameters) { |
---|
395 | G4cout << "\n " << *sceneList [iScene]; |
---|
396 | } |
---|
397 | G4cout << G4endl; |
---|
398 | } |
---|
399 | if (!found) { |
---|
400 | G4cout << "No scenes found"; |
---|
401 | if (name != "all") { |
---|
402 | G4cout << " of name \"" << name << "\""; |
---|
403 | } |
---|
404 | G4cout << "." << G4endl; |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | ////////////// /vis/scene/notifyHandlers ///////////////////////// |
---|
409 | |
---|
410 | G4VisCommandSceneNotifyHandlers::G4VisCommandSceneNotifyHandlers () { |
---|
411 | G4bool omitable; |
---|
412 | fpCommand = new G4UIcommand ("/vis/scene/notifyHandlers", this); |
---|
413 | fpCommand -> SetGuidance |
---|
414 | ("Notifies scene handlers and forces re-rendering."); |
---|
415 | fpCommand -> SetGuidance |
---|
416 | ("Notifies the handler(s) of the specified scene and forces a" |
---|
417 | "\nreconstruction of any graphical databases." |
---|
418 | "\nClears and refreshes all viewers of current scene." |
---|
419 | "\n The default action \"refresh\" does not issue \"update\" (see" |
---|
420 | "\n /vis/viewer/update)." |
---|
421 | "\nIf \"flush\" is specified, it issues an \"update\" as well as" |
---|
422 | "\n \"refresh\" - \"update\" and initiates post-processing" |
---|
423 | "\n for graphics systems which need it."); |
---|
424 | fpCommand -> SetGuidance |
---|
425 | ("The default for <scene-name> is the current scene name."); |
---|
426 | fpCommand -> SetGuidance |
---|
427 | ("This command does not change current scene, scene handler or viewer."); |
---|
428 | G4UIparameter* parameter; |
---|
429 | parameter = new G4UIparameter ("scene-name", 's', |
---|
430 | omitable = true); |
---|
431 | parameter -> SetCurrentAsDefault(true); |
---|
432 | fpCommand -> SetParameter (parameter); |
---|
433 | parameter = new G4UIparameter ("refresh-flush", 's', |
---|
434 | omitable = true); |
---|
435 | parameter -> SetDefaultValue("refresh"); |
---|
436 | parameter -> SetParameterCandidates("r refresh f flush"); |
---|
437 | fpCommand -> SetParameter (parameter); |
---|
438 | } |
---|
439 | |
---|
440 | G4VisCommandSceneNotifyHandlers::~G4VisCommandSceneNotifyHandlers () { |
---|
441 | delete fpCommand; |
---|
442 | } |
---|
443 | |
---|
444 | G4String G4VisCommandSceneNotifyHandlers::GetCurrentValue(G4UIcommand*) { |
---|
445 | return CurrentSceneName (); |
---|
446 | } |
---|
447 | |
---|
448 | void G4VisCommandSceneNotifyHandlers::SetNewValue (G4UIcommand*, |
---|
449 | G4String newValue) { |
---|
450 | |
---|
451 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
452 | |
---|
453 | G4String sceneName, refresh_flush; |
---|
454 | std::istringstream is (newValue); |
---|
455 | is >> sceneName >> refresh_flush; |
---|
456 | G4bool flush = false; |
---|
457 | if (refresh_flush(0) == 'f') flush = true; |
---|
458 | |
---|
459 | const G4SceneList& sceneList = fpVisManager -> GetSceneList (); |
---|
460 | G4SceneHandlerList& sceneHandlerList = |
---|
461 | fpVisManager -> SetAvailableSceneHandlers (); |
---|
462 | |
---|
463 | // Check scene name. |
---|
464 | const G4int nScenes = sceneList.size (); |
---|
465 | G4int iScene; |
---|
466 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
467 | G4Scene* scene = sceneList [iScene]; |
---|
468 | if (sceneName == scene -> GetName ()) break; |
---|
469 | } |
---|
470 | if (iScene >= nScenes ) { |
---|
471 | if (verbosity >= G4VisManager::warnings) { |
---|
472 | G4cout << "WARNING: Scene \"" << sceneName << "\" not found." |
---|
473 | "\n /vis/scene/list to see scenes." |
---|
474 | << G4endl; |
---|
475 | } |
---|
476 | return; |
---|
477 | } |
---|
478 | |
---|
479 | // Store current context... |
---|
480 | G4VSceneHandler* pCurrentSceneHandler = |
---|
481 | fpVisManager -> GetCurrentSceneHandler(); |
---|
482 | if (!pCurrentSceneHandler) { |
---|
483 | if (verbosity >= G4VisManager::warnings) { |
---|
484 | G4cout << "WARNING: No current scene handler." |
---|
485 | << G4endl; |
---|
486 | } |
---|
487 | return; |
---|
488 | } |
---|
489 | G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer(); |
---|
490 | if (!pCurrentViewer) { |
---|
491 | if (verbosity >= G4VisManager::warnings) { |
---|
492 | G4cout << "WARNING: No current viewer." |
---|
493 | << G4endl; |
---|
494 | } |
---|
495 | return; |
---|
496 | } |
---|
497 | G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene(); |
---|
498 | if (!pCurrentScene) { |
---|
499 | if (verbosity >= G4VisManager::warnings) { |
---|
500 | G4cout << "WARNING: No current scene." |
---|
501 | << G4endl; |
---|
502 | } |
---|
503 | return; |
---|
504 | } |
---|
505 | G4VisManager::Verbosity currentVerbosity = fpVisManager -> GetVerbosity(); |
---|
506 | |
---|
507 | // Suppress messages during this process (only print errors)... |
---|
508 | //fpVisManager -> SetVerboseLevel(G4VisManager::errors); |
---|
509 | |
---|
510 | // For each scene handler, if it contains the scene, clear and |
---|
511 | // rebuild the graphical database, then for each viewer set (make |
---|
512 | // current), clear, (re)draw, and show. |
---|
513 | const G4int nSceneHandlers = sceneHandlerList.size (); |
---|
514 | for (G4int iSH = 0; iSH < nSceneHandlers; iSH++) { |
---|
515 | G4VSceneHandler* aSceneHandler = sceneHandlerList [iSH]; |
---|
516 | G4Scene* aScene = aSceneHandler -> GetScene (); |
---|
517 | if (aScene) { |
---|
518 | const G4String& aSceneName = aScene -> GetName (); |
---|
519 | if (sceneName == aSceneName) { |
---|
520 | // Clear store and force a rebuild of graphical database... |
---|
521 | //aSceneHandler -> ClearStore (); // Not nec?? Done below |
---|
522 | //with NeedKernelVisit and DrawView. JA. |
---|
523 | G4ViewerList& viewerList = aSceneHandler -> SetViewerList (); |
---|
524 | const G4int nViewers = viewerList.size (); |
---|
525 | for (G4int iV = 0; iV < nViewers; iV++) { |
---|
526 | G4VViewer* aViewer = viewerList [iV]; |
---|
527 | if (aViewer->GetViewParameters().IsAutoRefresh()) { |
---|
528 | aSceneHandler -> SetCurrentViewer (aViewer); |
---|
529 | // Ensure consistency of vis manager... |
---|
530 | fpVisManager -> SetCurrentViewer(aViewer); |
---|
531 | fpVisManager -> SetCurrentSceneHandler(aSceneHandler); |
---|
532 | fpVisManager -> SetCurrentScene(aScene); |
---|
533 | // Re-draw, forcing rebuild of graphics database, if any... |
---|
534 | aViewer -> NeedKernelVisit(); |
---|
535 | aViewer -> SetView (); |
---|
536 | aViewer -> ClearView (); |
---|
537 | aViewer -> DrawView (); |
---|
538 | if (flush) aViewer -> ShowView (); |
---|
539 | if (verbosity >= G4VisManager::confirmations) { |
---|
540 | G4cout << "Viewer \"" << aViewer -> GetName () |
---|
541 | << "\" of scene handler \"" << aSceneHandler -> GetName () |
---|
542 | << "\"\n "; |
---|
543 | if (flush) G4cout << "flushed"; |
---|
544 | else G4cout << "refreshed"; |
---|
545 | G4cout << " at request of scene \"" << sceneName |
---|
546 | << "\"." << G4endl; |
---|
547 | } |
---|
548 | } else { |
---|
549 | if (verbosity >= G4VisManager::warnings) { |
---|
550 | G4cout << "WARNING: The scene, \"" |
---|
551 | << sceneName |
---|
552 | << "\", of viewer \"" |
---|
553 | << aViewer -> GetName () |
---|
554 | << "\"\n of scene handler \"" |
---|
555 | << aSceneHandler -> GetName () |
---|
556 | << "\" has changed. To see effect," |
---|
557 | << "\n \"/vis/viewer/select " |
---|
558 | << aViewer -> GetShortName () |
---|
559 | << "\" and \"/vis/viewer/rebuild\"." |
---|
560 | << G4endl; |
---|
561 | } |
---|
562 | } |
---|
563 | } |
---|
564 | } |
---|
565 | } |
---|
566 | else { |
---|
567 | if (verbosity >= G4VisManager::warnings) { |
---|
568 | G4cout << "WARNING: G4VisCommandSceneNotifyHandlers: scene handler \"" |
---|
569 | << aSceneHandler->GetName() |
---|
570 | << "\" has a null scene." |
---|
571 | << G4endl; |
---|
572 | } |
---|
573 | } |
---|
574 | } |
---|
575 | |
---|
576 | // Reclaim original context - but set viewer first, then scene |
---|
577 | // handler, because the latter might have been created very recently |
---|
578 | // and, not yet having a viewer, the current viewer will, |
---|
579 | // temporarily, refer to another scene handler. SetCurrentViewer |
---|
580 | // actually resets the scene handler, which is what we don't want, |
---|
581 | // so we set it again on the next line... |
---|
582 | fpVisManager -> SetCurrentViewer(pCurrentViewer); |
---|
583 | fpVisManager -> SetCurrentSceneHandler(pCurrentSceneHandler); |
---|
584 | fpVisManager -> SetCurrentScene(pCurrentScene); |
---|
585 | fpVisManager -> SetVerboseLevel(currentVerbosity); |
---|
586 | // Take care of special case of scene handler with no viewer yet. |
---|
587 | if (pCurrentSceneHandler) { |
---|
588 | G4ViewerList& viewerList = pCurrentSceneHandler -> SetViewerList (); |
---|
589 | const G4int nViewers = viewerList.size (); |
---|
590 | if (nViewers) { |
---|
591 | pCurrentSceneHandler -> SetCurrentViewer (pCurrentViewer); |
---|
592 | if (pCurrentViewer && pCurrentSceneHandler->GetScene()) { |
---|
593 | pCurrentViewer -> SetView (); |
---|
594 | } |
---|
595 | } |
---|
596 | } |
---|
597 | } |
---|
598 | |
---|
599 | ////////////// /vis/scene/select /////////////////////////////////////// |
---|
600 | |
---|
601 | G4VisCommandSceneSelect::G4VisCommandSceneSelect () { |
---|
602 | G4bool omitable; |
---|
603 | fpCommand = new G4UIcmdWithAString ("/vis/scene/select", this); |
---|
604 | fpCommand -> SetGuidance ("Selects a scene"); |
---|
605 | fpCommand -> SetGuidance |
---|
606 | ("Makes the scene current. \"/vis/scene/list\" to see" |
---|
607 | "\n possible scene names."); |
---|
608 | fpCommand -> SetParameterName ("scene-name", omitable = false); |
---|
609 | } |
---|
610 | |
---|
611 | G4VisCommandSceneSelect::~G4VisCommandSceneSelect () { |
---|
612 | delete fpCommand; |
---|
613 | } |
---|
614 | |
---|
615 | G4String G4VisCommandSceneSelect::GetCurrentValue (G4UIcommand*) { |
---|
616 | return ""; |
---|
617 | } |
---|
618 | |
---|
619 | void G4VisCommandSceneSelect::SetNewValue (G4UIcommand*, G4String newValue) { |
---|
620 | |
---|
621 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
622 | |
---|
623 | G4String& selectName = newValue; |
---|
624 | G4SceneList& sceneList = fpVisManager -> SetSceneList (); |
---|
625 | G4int iScene, nScenes = sceneList.size (); |
---|
626 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
627 | if (sceneList [iScene] -> GetName () == selectName) break; |
---|
628 | } |
---|
629 | if (iScene >= nScenes) { |
---|
630 | if (verbosity >= G4VisManager::warnings) { |
---|
631 | G4cout << "WARNING: Scene \"" << selectName |
---|
632 | << "\" not found - \"/vis/scene/list\" to see possibilities." |
---|
633 | << G4endl; |
---|
634 | } |
---|
635 | return; |
---|
636 | } |
---|
637 | |
---|
638 | if (verbosity >= G4VisManager::confirmations) { |
---|
639 | G4cout << "Scene \"" << selectName |
---|
640 | << "\" selected." << G4endl; |
---|
641 | } |
---|
642 | UpdateVisManagerScene (selectName); |
---|
643 | } |
---|