source: trunk/geant4/visualization/management/src/G4VisCommandsViewer.cc@ 543

Last change on this file since 543 was 531, checked in by garnier, 18 years ago

r660@mac-90108: laurentgarnier | 2007-06-25 16:10:12 +0200
ajout de fichiers NON modifies

  • Property svn:mime-type set to text/cpp
File size: 49.4 KB
Line 
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: G4VisCommandsViewer.cc,v 1.66 2006/11/25 15:38:03 allison Exp $
28// GEANT4 tag $Name: geant4-08-02-patch-01 $
29
30// /vis/viewer commands - John Allison 25th October 1998
31
32#include "G4VisCommandsViewer.hh"
33
34#include "G4VisManager.hh"
35#include "G4GraphicsSystemList.hh"
36#include "G4VisCommandsScene.hh"
37#include "G4UImanager.hh"
38#include "G4UIcommand.hh"
39#include "G4UIcmdWithoutParameter.hh"
40#include "G4UIcmdWithAString.hh"
41#include "G4UIcmdWithADouble.hh"
42#include "G4UIcmdWithADoubleAndUnit.hh"
43#include "G4UIcmdWith3Vector.hh"
44#include "G4UnitsTable.hh"
45#include "G4ios.hh"
46#include <sstream>
47
48G4VVisCommandViewer::G4VVisCommandViewer () {}
49
50G4VVisCommandViewer::~G4VVisCommandViewer () {}
51
52void G4VVisCommandViewer::SetViewParameters
53(G4VViewer* viewer, const G4ViewParameters& viewParams) {
54 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
55 viewer->SetViewParameters(viewParams);
56 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
57 if (sceneHandler && sceneHandler->GetScene()) {
58 if (viewParams.IsAutoRefresh()) {
59 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
60 }
61 else {
62 if (verbosity >= G4VisManager::confirmations) {
63 G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
64 }
65 }
66 }
67}
68
69////////////// /vis/viewer/addCutawayPlane ///////////////////////////////////////
70
71G4VisCommandViewerAddCutawayPlane::G4VisCommandViewerAddCutawayPlane () {
72 G4bool omitable;
73 fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
74 fpCommand -> SetGuidance
75 ("Add cutaway plane A*x + B*y + C*z + D = 0 to current viewer.");
76 G4UIparameter* parameter;
77 parameter = new G4UIparameter("x",'d',omitable = true);
78 parameter -> SetDefaultValue (0);
79 parameter -> SetGuidance ("Coordinate of point on the plane.");
80 fpCommand->SetParameter(parameter);
81 parameter = new G4UIparameter("y",'d',omitable = true);
82 parameter -> SetDefaultValue (0);
83 parameter -> SetGuidance ("Coordinate of point on the plane.");
84 fpCommand->SetParameter(parameter);
85 parameter = new G4UIparameter("z",'d',omitable = true);
86 parameter -> SetDefaultValue (0);
87 parameter -> SetGuidance ("Coordinate of point on the plane.");
88 fpCommand->SetParameter(parameter);
89 parameter = new G4UIparameter("unit",'s',omitable = true);
90 parameter -> SetDefaultValue ("m");
91 parameter -> SetGuidance ("Unit of point on the plane.");
92 fpCommand->SetParameter(parameter);
93 parameter = new G4UIparameter("nx",'d',omitable = true);
94 parameter -> SetDefaultValue (1);
95 parameter -> SetGuidance ("Component of plane normal.");
96 fpCommand->SetParameter(parameter);
97 parameter = new G4UIparameter("ny",'d',omitable = true);
98 parameter -> SetDefaultValue (0);
99 parameter -> SetGuidance ("Component of plane normal.");
100 fpCommand->SetParameter(parameter);
101 parameter = new G4UIparameter("nz",'d',omitable = true);
102 parameter -> SetDefaultValue (0);
103 parameter -> SetGuidance ("Component of plane normal.");
104 fpCommand->SetParameter(parameter);
105}
106
107G4VisCommandViewerAddCutawayPlane::~G4VisCommandViewerAddCutawayPlane () {
108 delete fpCommand;
109}
110
111G4String G4VisCommandViewerAddCutawayPlane::GetCurrentValue (G4UIcommand*) {
112 return "";
113}
114
115void G4VisCommandViewerAddCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
116
117 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
118
119 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
120 if (!viewer) {
121 if (verbosity >= G4VisManager::errors) {
122 G4cout <<
123 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
124 << G4endl;
125 }
126 return;
127 }
128
129 G4double x, y, z, nx, ny, nz;
130 G4String unit;
131 std::istringstream is (newValue);
132 is >> x >> y >> z >> unit >> nx >> ny >> nz;
133 G4double F = G4UIcommand::ValueOf(unit);
134 x *= F; y *= F; z *= F;
135
136 G4ViewParameters vp = viewer->GetViewParameters();
137 vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
138 if (verbosity >= G4VisManager::confirmations) {
139 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
140 const G4Planes& cutaways = vp.GetCutawayPlanes();
141 for (size_t i = 0; i < cutaways.size(); ++i)
142 G4cout << "\n " << i << ": " << cutaways[i];
143 G4cout << G4endl;
144 }
145
146 SetViewParameters(viewer, vp);
147}
148
149////////////// /vis/viewer/changeCutawayPlane ///////////////////////////////////////
150
151G4VisCommandViewerChangeCutawayPlane::G4VisCommandViewerChangeCutawayPlane () {
152 G4bool omitable;
153 fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
154 fpCommand -> SetGuidance("Change cutaway plane.");
155 G4UIparameter* parameter;
156 parameter = new G4UIparameter("index",'i',omitable = false);
157 parameter -> SetGuidance ("Index of plane: 0, 1, 2.");
158 fpCommand->SetParameter(parameter);
159 parameter = new G4UIparameter("x",'d',omitable = true);
160 parameter -> SetDefaultValue (0);
161 parameter -> SetGuidance ("Coordinate of point on the plane.");
162 fpCommand->SetParameter(parameter);
163 parameter = new G4UIparameter("y",'d',omitable = true);
164 parameter -> SetDefaultValue (0);
165 parameter -> SetGuidance ("Coordinate of point on the plane.");
166 fpCommand->SetParameter(parameter);
167 parameter = new G4UIparameter("z",'d',omitable = true);
168 parameter -> SetDefaultValue (0);
169 parameter -> SetGuidance ("Coordinate of point on the plane.");
170 fpCommand->SetParameter(parameter);
171 parameter = new G4UIparameter("unit",'s',omitable = true);
172 parameter -> SetDefaultValue ("m");
173 parameter -> SetGuidance ("Unit of point on the plane.");
174 fpCommand->SetParameter(parameter);
175 parameter = new G4UIparameter("nx",'d',omitable = true);
176 parameter -> SetDefaultValue (1);
177 parameter -> SetGuidance ("Component of plane normal.");
178 fpCommand->SetParameter(parameter);
179 parameter = new G4UIparameter("ny",'d',omitable = true);
180 parameter -> SetDefaultValue (0);
181 parameter -> SetGuidance ("Component of plane normal.");
182 fpCommand->SetParameter(parameter);
183 parameter = new G4UIparameter("nz",'d',omitable = true);
184 parameter -> SetDefaultValue (0);
185 parameter -> SetGuidance ("Component of plane normal.");
186 fpCommand->SetParameter(parameter);
187}
188
189G4VisCommandViewerChangeCutawayPlane::~G4VisCommandViewerChangeCutawayPlane () {
190 delete fpCommand;
191}
192
193G4String G4VisCommandViewerChangeCutawayPlane::GetCurrentValue (G4UIcommand*) {
194 return "";
195}
196
197void G4VisCommandViewerChangeCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
198
199 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
200
201 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
202 if (!viewer) {
203 if (verbosity >= G4VisManager::errors) {
204 G4cout <<
205 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
206 << G4endl;
207 }
208 return;
209 }
210
211 size_t index;
212 G4double x, y, z, nx, ny, nz;
213 G4String unit;
214 std::istringstream is (newValue);
215 is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
216 G4double F = G4UIcommand::ValueOf(unit);
217 x *= F; y *= F; z *= F;
218
219 G4ViewParameters vp = viewer->GetViewParameters();
220 vp.ChangeCutawayPlane(index,
221 G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
222 if (verbosity >= G4VisManager::confirmations) {
223 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
224 const G4Planes& cutaways = vp.GetCutawayPlanes();
225 for (size_t i = 0; i < cutaways.size(); ++i)
226 G4cout << "\n " << i << ": " << cutaways[i];
227 G4cout << G4endl;
228 }
229
230 SetViewParameters(viewer, vp);
231}
232
233////////////// /vis/viewer/clear ///////////////////////////////////////
234
235G4VisCommandViewerClear::G4VisCommandViewerClear () {
236 G4bool omitable, currentAsDefault;
237 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
238 fpCommand -> SetGuidance ("Clears viewer.");
239 fpCommand -> SetGuidance
240 ("By default, clears current viewer. Specified viewer becomes current."
241 "\n\"/vis/viewer/list\" to see possible viewer names.");
242 fpCommand -> SetParameterName ("viewer-name",
243 omitable = true,
244 currentAsDefault = true);
245}
246
247G4VisCommandViewerClear::~G4VisCommandViewerClear () {
248 delete fpCommand;
249}
250
251G4String G4VisCommandViewerClear::GetCurrentValue (G4UIcommand*) {
252 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
253 return viewer ? viewer -> GetName () : G4String("none");
254}
255
256void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) {
257
258 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
259
260 G4String& clearName = newValue;
261 G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
262 if (!viewer) {
263 if (verbosity >= G4VisManager::errors) {
264 G4cout << "ERROR: Viewer \"" << clearName
265 << "\" not found - \"/vis/viewer/list\" to see possibilities."
266 << G4endl;
267 }
268 return;
269 }
270
271 viewer->ClearView();
272 viewer->FinishView();
273 if (verbosity >= G4VisManager::confirmations) {
274 G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
275 }
276
277}
278
279////////////// /vis/viewer/clearCutawayPlanes ///////////////////////////////////////
280
281G4VisCommandViewerClearCutawayPlanes::G4VisCommandViewerClearCutawayPlanes () {
282 fpCommand = new G4UIcmdWithoutParameter
283 ("/vis/viewer/clearCutawayPlanes", this);
284 fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
285}
286
287G4VisCommandViewerClearCutawayPlanes::~G4VisCommandViewerClearCutawayPlanes () {
288 delete fpCommand;
289}
290
291G4String G4VisCommandViewerClearCutawayPlanes::GetCurrentValue (G4UIcommand*) {
292 return "";
293}
294
295void G4VisCommandViewerClearCutawayPlanes::SetNewValue (G4UIcommand*, G4String) {
296
297 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
298
299 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
300 if (!viewer) {
301 if (verbosity >= G4VisManager::errors) {
302 G4cout <<
303 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
304 << G4endl;
305 }
306 return;
307 }
308
309 G4ViewParameters vp = viewer->GetViewParameters();
310 vp.ClearCutawayPlanes();
311 if (verbosity >= G4VisManager::confirmations) {
312 G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
313 << "\" now cleared." << G4endl;
314 }
315
316 SetViewParameters(viewer, vp);
317}
318
319////////////// /vis/viewer/clearTransients //////////////////////////
320
321G4VisCommandViewerClearTransients::G4VisCommandViewerClearTransients () {
322 G4bool omitable, currentAsDefault;
323 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
324 fpCommand -> SetGuidance ("Clears transients from viewer.");
325 fpCommand -> SetGuidance
326 ("By default, operates on current viewer. Specified viewer becomes current."
327 "\n\"/vis/viewer/list\" to see possible viewer names.");
328 fpCommand -> SetParameterName ("viewer-name",
329 omitable = true,
330 currentAsDefault = true);
331}
332
333G4VisCommandViewerClearTransients::~G4VisCommandViewerClearTransients () {
334 delete fpCommand;
335}
336
337G4String G4VisCommandViewerClearTransients::GetCurrentValue (G4UIcommand*) {
338 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
339 return viewer ? viewer -> GetName () : G4String("none");
340}
341
342void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newValue) {
343
344 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
345
346 G4String& clearName = newValue;
347 G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
348 if (!viewer) {
349 if (verbosity >= G4VisManager::errors) {
350 G4cout << "ERROR: Viewer \"" << clearName
351 << "\" not found - \"/vis/viewer/list\" to see possibilities."
352 << G4endl;
353 }
354 return;
355 }
356
357 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
358 sceneHandler->SetMarkForClearingTransientStore(false);
359 fpVisManager->ResetTransientsDrawnFlags();
360 sceneHandler->ClearTransientStore();
361 if (verbosity >= G4VisManager::confirmations) {
362 G4cout << "Viewer \"" << clearName << "\" cleared of transients."
363 << G4endl;
364 }
365
366}
367
368////////////// /vis/viewer/clone ///////////////////////////////////////
369
370G4VisCommandViewerClone::G4VisCommandViewerClone () {
371 G4bool omitable;
372 fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
373 fpCommand -> SetGuidance ("Clones viewer.");
374 fpCommand -> SetGuidance
375 ("By default, clones current viewer. Clone becomes current."
376 "\nClone name, if not provided, is derived from the original name."
377 "\n\"/vis/viewer/list\" to see possible viewer names.");
378 G4UIparameter* parameter;
379 parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
380 parameter -> SetCurrentAsDefault (true);
381 fpCommand -> SetParameter (parameter);
382 parameter = new G4UIparameter ("clone-name", 's', omitable = true);
383 parameter -> SetDefaultValue ("none");
384 fpCommand -> SetParameter (parameter);
385}
386
387G4VisCommandViewerClone::~G4VisCommandViewerClone () {
388 delete fpCommand;
389}
390
391G4String G4VisCommandViewerClone::GetCurrentValue (G4UIcommand*) {
392 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
393 G4String originalName = viewer ? viewer -> GetName () : G4String("none");
394 return "\"" + originalName + "\"";
395}
396
397void G4VisCommandViewerClone::SetNewValue (G4UIcommand*, G4String newValue) {
398
399 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
400
401 G4String originalName, cloneName;
402 std::istringstream is (newValue);
403
404 // Need to handle the possibility that the names contain embedded
405 // blanks within quotation marks...
406 char c;
407 while (is.get(c) && c == ' ');
408 if (c == '"') {
409 while (is.get(c) && c != '"') originalName += c;
410 }
411 else {
412 originalName += c;
413 while (is.get(c) && c != ' ') originalName += c;
414 }
415 originalName = originalName.strip (G4String::both, ' ');
416 originalName = originalName.strip (G4String::both, '"');
417
418 G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
419 if (!originalViewer) {
420 if (verbosity >= G4VisManager::errors) {
421 G4cout << "ERROR: Viewer \"" << originalName
422 << "\" not found - \"/vis/viewer/list\" to see possibilities."
423 << G4endl;
424 }
425 return;
426 }
427 originalName = originalViewer->GetName(); // Ensures long name.
428
429 while (is.get(c) && c == ' ');
430 if (c == '"') {
431 while (is.get(c) && c != '"') cloneName += c;
432 }
433 else {
434 cloneName += c;
435 while (is.get(c) && c != ' ') cloneName += c;
436 }
437 cloneName = cloneName.strip (G4String::both, ' ');
438 cloneName = cloneName.strip (G4String::both, '"');
439
440 if (cloneName == "none") {
441 G4int subID = 0;
442 do {
443 cloneName = originalName;
444 std::ostringstream oss;
445 oss << '-' << subID++;
446 G4String::size_type lastDashPosition, nextSpacePosition;
447 if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos &&
448 (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
449 G4String::npos) {
450 cloneName.insert(nextSpacePosition, oss.str());
451 } else {
452 cloneName.insert(cloneName.find(' '), oss.str());
453 }
454 } while (fpVisManager -> GetViewer (cloneName));
455 }
456
457 if (fpVisManager -> GetViewer (cloneName)) {
458 if (verbosity >= G4VisManager::errors) {
459 G4cout << "ERROR: Putative clone viewer \"" << cloneName
460 << "\" already exists."
461 << G4endl;
462 }
463 return;
464 }
465
466 G4String windowSizeHint =
467 originalViewer->GetViewParameters().GetXGeometryString();
468
469 G4UImanager* UImanager = G4UImanager::GetUIpointer();
470 G4int keepVerbose = UImanager->GetVerboseLevel();
471 G4int newVerbose(0);
472 if (keepVerbose >= 2 ||
473 fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
474 newVerbose = 2;
475 UImanager->SetVerboseLevel(newVerbose);
476 UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
477 UImanager->ApplyCommand
478 (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
479 UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
480 UImanager->SetVerboseLevel(keepVerbose);
481
482 if (verbosity >= G4VisManager::confirmations) {
483 G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
484 G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
485 }
486}
487
488////////////// /vis/viewer/create ///////////////////////////////////////
489
490G4VisCommandViewerCreate::G4VisCommandViewerCreate (): fId (0) {
491 G4bool omitable;
492 fpCommand = new G4UIcommand ("/vis/viewer/create", this);
493 fpCommand -> SetGuidance
494 ("Creates a viewer for the specified scene handler.");
495 fpCommand -> SetGuidance
496 ("Default scene handler is the current scene handler. Invents a name"
497 "\nif not supplied. (Note: the system adds information to the name"
498 "\nfor identification - only the characters up to the first blank are"
499 "\nused for removing, selecting, etc.) This scene handler and viewer"
500 "\nbecome current.");
501 G4UIparameter* parameter;
502 parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
503 parameter -> SetCurrentAsDefault (true);
504 fpCommand -> SetParameter (parameter);
505 parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
506 parameter -> SetCurrentAsDefault (true);
507 fpCommand -> SetParameter (parameter);
508 parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
509 parameter->SetGuidance
510 ("integer (pixels) for square window placed by window manager or"
511 " X-Windows-type geometry string, e.g. 600x600-100+100");
512 parameter->SetDefaultValue("600");
513 fpCommand -> SetParameter (parameter);
514}
515
516G4VisCommandViewerCreate::~G4VisCommandViewerCreate () {
517 delete fpCommand;
518}
519
520G4String G4VisCommandViewerCreate::NextName () {
521 std::ostringstream oss;
522 G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
523 oss << "viewer-" << fId << " (";
524 if (sceneHandler) {
525 oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
526 }
527 else {
528 oss << "no_scene_handlers";
529 }
530 oss << ")";
531 return oss.str();
532}
533
534G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) {
535 G4String currentValue;
536 G4VSceneHandler* currentSceneHandler =
537 fpVisManager -> GetCurrentSceneHandler ();
538 if (currentSceneHandler) {
539 currentValue = currentSceneHandler -> GetName ();
540 }
541 else {
542 currentValue = "none";
543 }
544 currentValue += ' ';
545 currentValue += '"';
546 currentValue += NextName ();
547 currentValue += '"';
548
549 currentValue += " 600"; // Default number of pixels for window size hint.
550
551 return currentValue;
552}
553
554void G4VisCommandViewerCreate::SetNewValue (G4UIcommand*, G4String newValue) {
555
556 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
557
558 G4String sceneHandlerName, newName;
559 G4String windowSizeHintString;
560 std::istringstream is (newValue);
561 is >> sceneHandlerName;
562
563 // Now need to handle the possibility that the second string
564 // contains embedded blanks within quotation marks...
565 char c;
566 while (is.get(c) && c == ' ');
567 if (c == '"') {
568 while (is.get(c) && c != '"') newName += c;
569 }
570 else {
571 newName += c;
572 while (is.get(c) && c != ' ') newName += c;
573 }
574 newName = newName.strip (G4String::both, ' ');
575 newName = newName.strip (G4String::both, '"');
576
577 // Now get window size hint...
578 is >> windowSizeHintString;
579
580 const G4SceneHandlerList& sceneHandlerList =
581 fpVisManager -> GetAvailableSceneHandlers ();
582 G4int nHandlers = sceneHandlerList.size ();
583 if (nHandlers <= 0) {
584 if (verbosity >= G4VisManager::errors) {
585 G4cout <<
586 "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
587 "\n Create a scene handler with \"/vis/sceneHandler/create\""
588 << G4endl;
589 }
590 return;
591 }
592
593 G4int iHandler;
594 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
595 if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
596 }
597
598 if (iHandler < 0 || iHandler >= nHandlers) {
599 // Invalid command line argument or none.
600 // This shouldn't happen!!!!!!
601 if (verbosity >= G4VisManager::errors) {
602 G4cout << "G4VisCommandViewerCreate::SetNewValue:"
603 " invalid scene handler specified."
604 << G4endl;
605 }
606 return;
607 }
608
609 // Valid index. Set current scene handler and graphics system in
610 // preparation for creating viewer.
611 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
612 if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
613 fpVisManager -> SetCurrentSceneHandler (sceneHandler);
614 }
615
616 // Now deal with name of viewer.
617 G4String nextName = NextName ();
618 if (newName == "") {
619 newName = nextName;
620 }
621 if (newName == nextName) fId++;
622 G4String newShortName = fpVisManager -> ViewerShortName (newName);
623
624 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
625 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
626 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
627 for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
628 if (viewerList [iViewer] -> GetShortName () == newShortName ) {
629 if (verbosity >= G4VisManager::errors) {
630 G4cout << "ERROR: Viewer \"" << newShortName << "\" already exists."
631 << G4endl;
632 }
633 return;
634 }
635 }
636 }
637
638 // Parse windowSizeHintString to extract first field for backwards
639 // compatibility...
640 std::istringstream issw;
641 G4int windowSizeHint;
642 size_t i;
643 for (i = 0; i < windowSizeHintString.size(); ++i) {
644 char c = windowSizeHintString[i];
645 if (c == 'x' || c == 'X' || c == '+' || c == '-') break;
646 }
647 if (i != windowSizeHintString.size()) {
648 // x or X or + or - found - must be a X-Window-type geometry string...
649 // Pick out the first field for backwards compatibility...
650 issw.str(windowSizeHintString.substr(0,i));
651 issw >> windowSizeHint;
652 } else { // ...old-style integer...
653 issw.str(windowSizeHintString);
654 if (!(issw >> windowSizeHint)) {
655 if (verbosity >= G4VisManager::errors) {
656 G4cout << "ERROR: Unrecognised geometry string \""
657 << windowSizeHintString
658 << "\". Using 600."
659 << G4endl;
660 }
661 windowSizeHint = 600;
662 }
663 // Reconstitute windowSizeHintString...
664 std::ostringstream ossw;
665 ossw << windowSizeHint << 'x' << windowSizeHint;
666 windowSizeHintString = ossw.str();
667 }
668 fpVisManager->SetWindowSizeHint (windowSizeHint, windowSizeHint);
669 fpVisManager->SetXGeometryString(windowSizeHintString);
670 // WindowSizeHint and XGeometryString are picked up from the vis
671 // manager in the G4VViewer constructor. They have to be held by
672 // the vis manager until the viewer is contructed - next line...
673
674 // Create viewer.
675 fpVisManager -> CreateViewer (newName);
676 G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
677 if (newViewer && newViewer -> GetName () == newName) {
678 if (verbosity >= G4VisManager::confirmations) {
679 G4cout << "New viewer \"" << newName << "\" created." << G4endl;
680 }
681 }
682 else {
683 if (verbosity >= G4VisManager::errors) {
684 if (newViewer) {
685 G4cout << "ERROR: New viewer doesn\'t match!!! Curious!!" << G4endl;
686 } else {
687 G4cout << "WARNING: No viewer created." << G4endl;
688 }
689 }
690 }
691 // Refresh if appropriate...
692 if (newViewer) {
693 if (newViewer->GetViewParameters().IsAutoRefresh()) {
694 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
695 }
696 else {
697 if (verbosity >= G4VisManager::confirmations) {
698 G4cout << "Issue /vis/viewer/refresh to see effect." << G4endl;
699 }
700 }
701 }
702}
703
704////////////// /vis/viewer/dolly and dollyTo ////////////////////////////
705
706G4VisCommandViewerDolly::G4VisCommandViewerDolly ():
707 fDollyIncrement (0.),
708 fDollyTo (0.)
709{
710 G4bool omitable, currentAsDefault;
711
712 fpCommandDolly = new G4UIcmdWithADoubleAndUnit
713 ("/vis/viewer/dolly", this);
714 fpCommandDolly -> SetGuidance
715 ("Incremental dolly.");
716 fpCommandDolly -> SetGuidance
717 ("Moves the camera incrementally towards target point.");
718 fpCommandDolly -> SetParameterName("increment",
719 omitable=true,
720 currentAsDefault=true);
721 fpCommandDolly -> SetDefaultUnit("m");
722
723 fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
724 ("/vis/viewer/dollyTo", this);
725 fpCommandDollyTo -> SetGuidance
726 ("Dolly to specific coordinate.");
727 fpCommandDollyTo -> SetGuidance
728 ("Places the camera towards target point relative to standard camera point.");
729 fpCommandDollyTo -> SetParameterName("distance",
730 omitable=true,
731 currentAsDefault=true);
732 fpCommandDollyTo -> SetDefaultUnit("m");
733}
734
735G4VisCommandViewerDolly::~G4VisCommandViewerDolly () {
736 delete fpCommandDolly;
737 delete fpCommandDollyTo;
738}
739
740G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) {
741 G4String currentValue;
742 if (command == fpCommandDolly) {
743 currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
744 }
745 else if (command == fpCommandDollyTo) {
746 currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
747 }
748 return currentValue;
749}
750
751void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command,
752 G4String newValue) {
753
754
755 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
756
757 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
758 if (!currentViewer) {
759 if (verbosity >= G4VisManager::errors) {
760 G4cout <<
761 "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
762 << G4endl;
763 }
764 return;
765 }
766
767 G4ViewParameters vp = currentViewer->GetViewParameters();
768
769 if (command == fpCommandDolly) {
770 fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
771 vp.IncrementDolly(fDollyIncrement);
772 }
773 else if (command == fpCommandDollyTo) {
774 fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
775 vp.SetDolly(fDollyTo);
776 }
777
778 if (verbosity >= G4VisManager::confirmations) {
779 G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
780 }
781
782 SetViewParameters(currentViewer, vp);
783}
784
785////////////// /vis/viewer/flush ///////////////////////////////////////
786
787G4VisCommandViewerFlush::G4VisCommandViewerFlush () {
788 G4bool omitable, currentAsDefault;
789 fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
790 fpCommand -> SetGuidance
791 ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
792 fpCommand -> SetGuidance
793 ("Useful for refreshing and initiating post-processing for graphics"
794 "\nsystems which need post-processing. By default, acts on current"
795 "\nviewer. \"/vis/viewer/list\" to see possible viewers. Viewer"
796 "\nbecomes current.");
797 fpCommand -> SetParameterName ("viewer-name",
798 omitable = true,
799 currentAsDefault = true);
800}
801
802G4VisCommandViewerFlush::~G4VisCommandViewerFlush () {
803 delete fpCommand;
804}
805
806G4String G4VisCommandViewerFlush::GetCurrentValue
807(G4UIcommand*) {
808 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
809 return viewer ? viewer -> GetName () : G4String("none");
810}
811
812void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
813
814 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
815
816 G4String& flushName = newValue;
817 G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
818 if (!viewer) {
819 if (verbosity >= G4VisManager::errors) {
820 G4cout << "ERROR: Viewer \"" << flushName << "\"" <<
821 " not found - \"/vis/viewer/list\"\n to see possibilities."
822 << G4endl;
823 }
824 return;
825 }
826
827 G4UImanager* ui = G4UImanager::GetUIpointer();
828 G4int keepVerbose = ui->GetVerboseLevel();
829 G4int newVerbose(0);
830 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
831 newVerbose = 2;
832 ui->SetVerboseLevel(newVerbose);
833 ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
834 ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
835 ui->SetVerboseLevel(keepVerbose);
836 if (verbosity >= G4VisManager::confirmations) {
837 G4cout << "Viewer \"" << viewer -> GetName () << "\""
838 << " flushed." << G4endl;
839 }
840}
841
842////////////// /vis/viewer/list ///////////////////////////////////////
843
844G4VisCommandViewerList::G4VisCommandViewerList () {
845 G4bool omitable;
846 fpCommand = new G4UIcommand ("/vis/viewer/list", this);
847 fpCommand -> SetGuidance ("Lists viewers(s).");
848 fpCommand -> SetGuidance
849 ("See \"/vis/verbose\" for definition of verbosity.");
850 G4UIparameter* parameter;
851 parameter = new G4UIparameter("viewer-name", 's',
852 omitable = true);
853 parameter -> SetDefaultValue ("all");
854 fpCommand -> SetParameter (parameter);
855 parameter = new G4UIparameter ("verbosity", 's',
856 omitable = true);
857 parameter -> SetDefaultValue ("warnings");
858 fpCommand -> SetParameter (parameter);
859}
860
861G4VisCommandViewerList::~G4VisCommandViewerList () {
862 delete fpCommand;
863}
864
865G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) {
866 return "";
867}
868
869void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) {
870 G4String name, verbosityString;
871 std::istringstream is (newValue);
872 is >> name >> verbosityString;
873 G4String shortName = fpVisManager -> ViewerShortName (name);
874 G4VisManager::Verbosity verbosity =
875 fpVisManager->GetVerbosityValue(verbosityString);
876
877 const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
878 G4String currentViewerShortName;
879 if (currentViewer) {
880 currentViewerShortName = currentViewer -> GetShortName ();
881 }
882 else {
883 currentViewerShortName = "none";
884 }
885
886 const G4SceneHandlerList& sceneHandlerList = fpVisManager -> GetAvailableSceneHandlers ();
887 G4int nHandlers = sceneHandlerList.size ();
888 G4bool found = false;
889 G4bool foundCurrent = false;
890 for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
891 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
892 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
893 G4cout << "Scene handler \"" << sceneHandler -> GetName ();
894 const G4Scene* pScene = sceneHandler -> GetScene ();
895 if (pScene) {
896 G4cout << "\", scene \"" << pScene -> GetName () << "\":";
897 }
898 G4int nViewers = viewerList.size ();
899 if (nViewers == 0) {
900 G4cout << "\n No viewers for this scene handler." << G4endl;
901 }
902 else {
903 for (int iViewer = 0; iViewer < nViewers; iViewer++) {
904 const G4VViewer* thisViewer = viewerList [iViewer];
905 G4String thisName = thisViewer -> GetName ();
906 G4String thisShortName = thisViewer -> GetShortName ();
907 if (name != "all") {
908 if (thisShortName != shortName) continue;
909 }
910 found = true;
911 G4cout << "\n ";
912 if (thisShortName == currentViewerShortName) {
913 foundCurrent = true;
914 G4cout << "(current)";
915 }
916 else {
917 G4cout << " ";
918 }
919 G4cout << " viewer \"" << thisName << "\"";
920 if (verbosity >= G4VisManager::parameters) {
921 G4cout << "\n " << *thisViewer;
922 }
923 }
924 }
925 G4cout << G4endl;
926 }
927
928 if (!foundCurrent) {
929 G4cout << "No valid current viewer - please create or select one."
930 << G4endl;
931 }
932
933 if (!found) {
934 G4cout << "No viewers";
935 if (name != "all") {
936 G4cout << " of name \"" << name << "\"";
937 }
938 G4cout << " found." << G4endl;
939 }
940}
941
942////////////// /vis/viewer/pan and panTo ////////////////////////////
943
944G4VisCommandViewerPan::G4VisCommandViewerPan ():
945 fPanIncrementRight (0.),
946 fPanIncrementUp (0.),
947 fPanToRight (0.),
948 fPanToUp (0.)
949{
950 G4bool omitable;
951
952 fpCommandPan = new G4UIcommand
953 ("/vis/viewer/pan", this);
954 fpCommandPan -> SetGuidance
955 ("Incremental pan.");
956 fpCommandPan -> SetGuidance
957 ("Moves the camera incrementally right and up by these amounts (as seen"
958 "\nfrom viewpoint direction).");
959 G4UIparameter* parameter;
960 parameter = new G4UIparameter("right-increment", 'd', omitable = true);
961 parameter -> SetCurrentAsDefault (true);
962 fpCommandPan -> SetParameter (parameter);
963 parameter = new G4UIparameter("up-increment", 'd', omitable = true);
964 parameter -> SetCurrentAsDefault (true);
965 fpCommandPan -> SetParameter (parameter);
966 parameter = new G4UIparameter ("unit", 's', omitable = true);
967 parameter -> SetDefaultValue ("m");
968 fpCommandPan -> SetParameter (parameter);
969
970 fpCommandPanTo = new G4UIcommand
971 ("/vis/viewer/panTo", this);
972 fpCommandPanTo -> SetGuidance
973 ("Pan to specific coordinate.");
974 fpCommandPanTo -> SetGuidance
975 ("Places the camera in this position right and up relative to standard"
976 "\ntarget point (as seen from viewpoint direction).");
977 parameter = new G4UIparameter("right", 'd', omitable = true);
978 parameter -> SetCurrentAsDefault (true);
979 fpCommandPanTo -> SetParameter (parameter);
980 parameter = new G4UIparameter("up", 'd', omitable = true);
981 parameter -> SetCurrentAsDefault (true);
982 fpCommandPanTo -> SetParameter (parameter);
983 parameter = new G4UIparameter ("unit", 's', omitable = true);
984 parameter -> SetDefaultValue ("m");
985 fpCommandPanTo -> SetParameter (parameter);
986}
987
988G4VisCommandViewerPan::~G4VisCommandViewerPan () {
989 delete fpCommandPan;
990 delete fpCommandPanTo;
991}
992
993G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) {
994 G4String currentValue;
995 if (command == fpCommandPan) {
996 currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
997 }
998 else if (command == fpCommandPanTo) {
999 currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
1000 }
1001 return currentValue;
1002}
1003
1004void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command,
1005 G4String newValue) {
1006
1007
1008 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1009
1010 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1011 if (!currentViewer) {
1012 if (verbosity >= G4VisManager::errors) {
1013 G4cout <<
1014 "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
1015 << G4endl;
1016 }
1017 return;
1018 }
1019
1020 G4ViewParameters vp = currentViewer->GetViewParameters();
1021
1022 if (command == fpCommandPan) {
1023 ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp);
1024 vp.IncrementPan(fPanIncrementRight, fPanIncrementUp);
1025 }
1026 else if (command == fpCommandPanTo) {
1027 ConvertToDoublePair(newValue, fPanToRight, fPanToUp);
1028 vp.SetPan(fPanToRight, fPanToUp);
1029 }
1030
1031 if (verbosity >= G4VisManager::confirmations) {
1032 G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
1033 << G4endl;
1034 }
1035
1036 SetViewParameters(currentViewer, vp);
1037}
1038
1039////////////// /vis/viewer/rebuild ///////////////////////////////////////
1040
1041G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () {
1042 G4bool omitable, currentAsDefault;
1043 fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
1044 fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
1045 fpCommand -> SetGuidance
1046 ("By default, acts on current viewer. \"/vis/viewer/list\""
1047 "\nto see possible viewers. Viewer becomes current.");
1048 fpCommand -> SetParameterName ("viewer-name",
1049 omitable = true,
1050 currentAsDefault = true);
1051}
1052
1053G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () {
1054 delete fpCommand;
1055}
1056
1057G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) {
1058 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1059 if (viewer) {
1060 return viewer -> GetName ();
1061 }
1062 else {
1063 return "none";
1064 }
1065}
1066
1067void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) {
1068
1069 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1070
1071 G4String& rebuildName = newValue;
1072 G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
1073 if (!viewer) {
1074 if (verbosity >= G4VisManager::errors) {
1075 G4cout << "ERROR: Viewer \"" << rebuildName
1076 << "\" not found - \"/vis/viewer/list\" to see possibilities."
1077 << G4endl;
1078 }
1079 return;
1080 }
1081
1082 viewer->NeedKernelVisit();
1083
1084 // Check auto-refresh and print confirmations, but without changing
1085 // view paramters...
1086 SetViewParameters(viewer, viewer->GetViewParameters());
1087}
1088
1089////////////// /vis/viewer/refresh ///////////////////////////////////////
1090
1091G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () {
1092 G4bool omitable, currentAsDefault;
1093 fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
1094 fpCommand -> SetGuidance
1095 ("Refreshes viewer.");
1096 fpCommand -> SetGuidance
1097 ("By default, acts on current viewer. \"/vis/viewer/list\""
1098 "\nto see possible viewers. Viewer becomes current.");
1099 fpCommand -> SetParameterName ("viewer-name",
1100 omitable = true,
1101 currentAsDefault = true);
1102}
1103
1104G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () {
1105 delete fpCommand;
1106}
1107
1108G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) {
1109 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1110 return viewer ? viewer -> GetName () : G4String("none");
1111}
1112
1113void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) {
1114
1115 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1116 G4bool warn(verbosity >= G4VisManager::warnings);
1117
1118 G4String& refreshName = newValue;
1119 G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
1120 if (!viewer) {
1121 if (verbosity >= G4VisManager::errors) {
1122 G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
1123 " not found - \"/vis/viewer/list\"\n to see possibilities."
1124 << G4endl;
1125 }
1126 return;
1127 }
1128
1129 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1130 if (!sceneHandler) {
1131 if (verbosity >= G4VisManager::errors) {
1132 G4cout << "ERROR: Viewer \"" << refreshName << "\"" <<
1133 " has no scene handler - report serious bug."
1134 << G4endl;
1135 }
1136 return;
1137 }
1138
1139 G4Scene* scene = sceneHandler->GetScene();
1140 if (!scene) {
1141 if (verbosity >= G4VisManager::warnings) {
1142 G4cout << "WARNING: SceneHandler \"" << sceneHandler->GetName()
1143 << "\", to which viewer \"" << refreshName << "\"" <<
1144 "\n is attached, has no scene - \"/vis/scene/create\" and"
1145 " \"/vis/sceneHandler/attach\""
1146 "\n (or use compound command \"/vis/drawVolume\")."
1147 << G4endl;
1148 }
1149 return;
1150 }
1151 if (scene->GetRunDurationModelList().empty()) {
1152 G4bool successful = scene -> AddWorldIfEmpty (warn);
1153 if (!successful) {
1154 if (verbosity >= G4VisManager::warnings) {
1155 G4cout <<
1156 "WARNING: Scene is empty. Perhaps no geometry exists."
1157 "\n Try /run/initialize."
1158 << G4endl;
1159 }
1160 return;
1161 }
1162 // Scene has changed. UpdateVisManagerScene issues
1163 // /vis/scene/notifyHandlers, which does a refresh anyway, so the
1164 // ordinary refresh becomes part of the else phrase...
1165 UpdateVisManagerScene(scene->GetName());
1166 } else {
1167 if (verbosity >= G4VisManager::confirmations) {
1168 G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
1169 << G4endl;
1170 }
1171 viewer -> SetView ();
1172 viewer -> ClearView ();
1173 viewer -> DrawView ();
1174 if (verbosity >= G4VisManager::confirmations) {
1175 G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
1176 "\n (You might also need \"/vis/viewer/update\".)" << G4endl;
1177 }
1178 }
1179}
1180
1181////////////// /vis/viewer/reset ///////////////////////////////////////
1182
1183G4VisCommandViewerReset::G4VisCommandViewerReset () {
1184 G4bool omitable, currentAsDefault;
1185 fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
1186 fpCommand -> SetGuidance ("Resets viewer.");
1187 fpCommand -> SetGuidance
1188 ("By default, acts on current viewer. \"/vis/viewer/list\""
1189 "\nto see possible viewers. Viewer becomes current.");
1190 fpCommand -> SetParameterName ("viewer-name",
1191 omitable = true,
1192 currentAsDefault = true);
1193}
1194
1195G4VisCommandViewerReset::~G4VisCommandViewerReset () {
1196 delete fpCommand;
1197}
1198
1199G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) {
1200 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1201 if (viewer) {
1202 return viewer -> GetName ();
1203 }
1204 else {
1205 return "none";
1206 }
1207}
1208
1209void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) {
1210
1211 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1212
1213 G4String& resetName = newValue;
1214 G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
1215 if (!viewer) {
1216 if (verbosity >= G4VisManager::errors) {
1217 G4cout << "ERROR: Viewer \"" << resetName
1218 << "\" not found - \"/vis/viewer/list\" to see possibilities."
1219 << G4endl;
1220 }
1221 return;
1222 }
1223
1224 SetViewParameters(viewer, viewer->GetDefaultViewParameters());
1225}
1226
1227////////////// /vis/viewer/scale and scaleTo ////////////////////////////
1228
1229G4VisCommandViewerScale::G4VisCommandViewerScale ():
1230 fScaleMultiplier (G4Vector3D (1., 1., 1.)),
1231 fScaleTo (G4Vector3D (1., 1., 1.))
1232{
1233 G4bool omitable, currentAsDefault;
1234
1235 fpCommandScale = new G4UIcmdWith3Vector
1236 ("/vis/viewer/scale", this);
1237 fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
1238 fpCommandScale -> SetGuidance
1239 ("Multiplies components of current scaling by components of this factor."
1240 "\n Scales (x,y,z) by corresponding components of the resulting factor.");
1241 fpCommandScale -> SetGuidance
1242 ("");
1243 fpCommandScale -> SetParameterName
1244 ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
1245 omitable=true, currentAsDefault=true);
1246
1247 fpCommandScaleTo = new G4UIcmdWith3Vector
1248 ("/vis/viewer/scaleTo", this);
1249 fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
1250 fpCommandScaleTo -> SetGuidance
1251 ("Scales (x,y,z) by corresponding components of this factor.");
1252 fpCommandScaleTo -> SetParameterName
1253 ("x-scale-factor","y-scale-factor","z-scale-factor",
1254 omitable=true, currentAsDefault=true);
1255}
1256
1257G4VisCommandViewerScale::~G4VisCommandViewerScale () {
1258 delete fpCommandScale;
1259 delete fpCommandScaleTo;
1260}
1261
1262G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) {
1263 G4String currentValue;
1264 if (command == fpCommandScale) {
1265 currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
1266 }
1267 else if (command == fpCommandScaleTo) {
1268 currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
1269 }
1270 return currentValue;
1271}
1272
1273void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command,
1274 G4String newValue) {
1275
1276
1277 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1278
1279 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1280 if (!currentViewer) {
1281 if (verbosity >= G4VisManager::errors) {
1282 G4cout <<
1283 "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
1284 << G4endl;
1285 }
1286 return;
1287 }
1288
1289 G4ViewParameters vp = currentViewer->GetViewParameters();
1290
1291 if (command == fpCommandScale) {
1292 fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
1293 vp.MultiplyScaleFactor(fScaleMultiplier);
1294 }
1295 else if (command == fpCommandScaleTo) {
1296 fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
1297 vp.SetScaleFactor(fScaleTo);
1298 }
1299
1300 if (verbosity >= G4VisManager::confirmations) {
1301 G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
1302 }
1303
1304 SetViewParameters(currentViewer, vp);
1305}
1306
1307////////////// /vis/viewer/select ///////////////////////////////////////
1308
1309G4VisCommandViewerSelect::G4VisCommandViewerSelect () {
1310 G4bool omitable;
1311 fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
1312 fpCommand -> SetGuidance ("Selects viewer.");
1313 fpCommand -> SetGuidance
1314 ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers.");
1315 fpCommand -> SetParameterName ("viewer-name", omitable = false);
1316}
1317
1318G4VisCommandViewerSelect::~G4VisCommandViewerSelect () {
1319 delete fpCommand;
1320}
1321
1322G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) {
1323 return "";
1324}
1325
1326void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
1327
1328 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1329
1330 G4String& selectName = newValue;
1331 G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
1332
1333 if (!viewer) {
1334 if (verbosity >= G4VisManager::errors) {
1335 G4cout << "ERROR: Viewer \"" << selectName << "\"";
1336 G4cout << " not found - \"/vis/viewer/list\""
1337 "\n to see possibilities."
1338 << G4endl;
1339 }
1340 return;
1341 }
1342
1343 if (viewer == fpVisManager -> GetCurrentViewer ()) {
1344 if (verbosity >= G4VisManager::warnings) {
1345 G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
1346 << " already selected." << G4endl;
1347 }
1348 return;
1349 }
1350
1351 fpVisManager -> SetCurrentViewer (viewer); // Prints confirmation.
1352
1353 SetViewParameters(viewer, viewer->GetViewParameters());
1354}
1355
1356////////////// /vis/viewer/update ///////////////////////////////////////
1357
1358G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () {
1359 G4bool omitable, currentAsDefault;
1360 fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
1361 fpCommand -> SetGuidance
1362 ("Triggers graphical database post-processing for viewers"
1363 "\nusing that technique.");
1364 fpCommand -> SetGuidance
1365 ("For such viewers the view only becomes visible with this command."
1366 "\nBy default, acts on current viewer. \"/vis/viewer/list\""
1367 "\nto see possible viewers. Viewer becomes current.");
1368 fpCommand -> SetParameterName ("viewer-name",
1369 omitable = true,
1370 currentAsDefault = true);
1371}
1372
1373G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () {
1374 delete fpCommand;
1375}
1376
1377G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) {
1378 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1379 if (viewer) {
1380 return viewer -> GetName ();
1381 }
1382 else {
1383 return "none";
1384 }
1385}
1386
1387void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) {
1388
1389 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1390
1391 G4String& updateName = newValue;
1392
1393 G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
1394 if (!viewer) {
1395 if (verbosity >= G4VisManager::errors) {
1396 G4cout <<
1397 "ERROR: G4VisCommandsViewerUpdate::SetNewValue: no current viewer."
1398 << G4endl;
1399 }
1400 return;
1401 }
1402
1403 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1404 if (!sceneHandler) {
1405 if (verbosity >= G4VisManager::errors) {
1406 G4cout << "ERROR: Viewer \"" << updateName << "\"" <<
1407 " has no scene handler - report serious bug."
1408 << G4endl;
1409 }
1410 return;
1411 }
1412
1413 G4Scene* scene = sceneHandler->GetScene();
1414 if (!scene) {
1415 if (verbosity >= G4VisManager::warnings) {
1416 G4cout << "WARNING: SceneHandler \"" << sceneHandler->GetName()
1417 << "\", to which viewer \"" << updateName << "\"" <<
1418 "\n is attached, has no scene - \"/vis/scene/create\" and"
1419 " \"/vis/sceneHandler/attach\""
1420 "\n (or use compound command \"/vis/drawVolume\")."
1421 << G4endl;
1422 }
1423 return;
1424 }
1425
1426 if (viewer) {
1427 if (verbosity >= G4VisManager::confirmations) {
1428 G4cout << "Viewer \"" << viewer -> GetName () << "\"";
1429 G4cout << " post-processing triggered." << G4endl;
1430 }
1431 viewer -> ShowView ();
1432 // Assume future need to "refresh" transients...
1433 sceneHandler -> SetMarkForClearingTransientStore(true);
1434 }
1435 else {
1436 if (verbosity >= G4VisManager::errors) {
1437 G4cout << "ERROR: Viewer \"" << updateName << "\"";
1438 G4cout << " not found - \"/vis/viewer/list\""
1439 "\n to see possibilities." << G4endl;
1440 }
1441 }
1442}
1443
1444////////////// /vis/viewer/zoom and zoomTo ////////////////////////////
1445
1446G4VisCommandViewerZoom::G4VisCommandViewerZoom ():
1447 fZoomMultiplier (1.),
1448 fZoomTo (1.)
1449{
1450 G4bool omitable, currentAsDefault;
1451
1452 fpCommandZoom = new G4UIcmdWithADouble
1453 ("/vis/viewer/zoom", this);
1454 fpCommandZoom -> SetGuidance ("Incremental zoom.");
1455 fpCommandZoom -> SetGuidance
1456 ("Multiplies current magnification by this factor.");
1457 fpCommandZoom -> SetParameterName("multiplier",
1458 omitable=true,
1459 currentAsDefault=true);
1460
1461 fpCommandZoomTo = new G4UIcmdWithADouble
1462 ("/vis/viewer/zoomTo", this);
1463 fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
1464 fpCommandZoomTo -> SetGuidance
1465 ("Magnifies standard magnification by this factor.");
1466 fpCommandZoomTo -> SetParameterName("factor",
1467 omitable=true,
1468 currentAsDefault=true);
1469}
1470
1471G4VisCommandViewerZoom::~G4VisCommandViewerZoom () {
1472 delete fpCommandZoom;
1473 delete fpCommandZoomTo;
1474}
1475
1476G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) {
1477 G4String currentValue;
1478 if (command == fpCommandZoom) {
1479 currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
1480 }
1481 else if (command == fpCommandZoomTo) {
1482 currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
1483 }
1484 return currentValue;
1485}
1486
1487void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command,
1488 G4String newValue) {
1489
1490
1491 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1492
1493 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1494 if (!currentViewer) {
1495 if (verbosity >= G4VisManager::errors) {
1496 G4cout <<
1497 "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
1498 << G4endl;
1499 }
1500 return;
1501 }
1502
1503 G4ViewParameters vp = currentViewer->GetViewParameters();
1504
1505 if (command == fpCommandZoom) {
1506 fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
1507 vp.MultiplyZoomFactor(fZoomMultiplier);
1508 }
1509 else if (command == fpCommandZoomTo) {
1510 fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
1511 vp.SetZoomFactor(fZoomTo);
1512 }
1513
1514 if (verbosity >= G4VisManager::confirmations) {
1515 G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
1516 }
1517
1518 SetViewParameters(currentViewer, vp);
1519}
Note: See TracBrowser for help on using the repository browser.