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