Geant4-11
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
28// /vis/viewer commands - John Allison 25th October 1998
29
31
32#include "G4VisManager.hh"
34#include "G4VisCommandsScene.hh"
35#include "G4UImanager.hh"
36#include "G4UIcommand.hh"
38#include "G4UIcmdWithAString.hh"
39#include "G4UIcmdWithADouble.hh"
41#include "G4UIcmdWith3Vector.hh"
44#include "G4Point3D.hh"
45#include "G4SystemOfUnits.hh"
46#include "G4UnitsTable.hh"
47#include "G4Filesystem.hh"
48#include <chrono>
49#include <thread>
50#include <sstream>
51#include <fstream>
52#include <iomanip>
53#include <cstdio>
54#include <regex>
55#include <set>
56
58
60 G4bool omitable;
61 fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
62 fpCommand -> SetGuidance
63 ("Add cutaway plane to current viewer.");
64 G4UIparameter* parameter;
65 parameter = new G4UIparameter("x",'d',omitable = true);
66 parameter -> SetDefaultValue (0);
67 parameter -> SetGuidance ("Coordinate of point on the plane.");
68 fpCommand->SetParameter(parameter);
69 parameter = new G4UIparameter("y",'d',omitable = true);
70 parameter -> SetDefaultValue (0);
71 parameter -> SetGuidance ("Coordinate of point on the plane.");
72 fpCommand->SetParameter(parameter);
73 parameter = new G4UIparameter("z",'d',omitable = true);
74 parameter -> SetDefaultValue (0);
75 parameter -> SetGuidance ("Coordinate of point on the plane.");
76 fpCommand->SetParameter(parameter);
77 parameter = new G4UIparameter("unit",'s',omitable = true);
78 parameter -> SetDefaultValue ("m");
79 parameter -> SetGuidance ("Unit of point on the plane.");
80 fpCommand->SetParameter(parameter);
81 parameter = new G4UIparameter("nx",'d',omitable = true);
82 parameter -> SetDefaultValue (1);
83 parameter -> SetGuidance ("Component of plane normal.");
84 fpCommand->SetParameter(parameter);
85 parameter = new G4UIparameter("ny",'d',omitable = true);
86 parameter -> SetDefaultValue (0);
87 parameter -> SetGuidance ("Component of plane normal.");
88 fpCommand->SetParameter(parameter);
89 parameter = new G4UIparameter("nz",'d',omitable = true);
90 parameter -> SetDefaultValue (0);
91 parameter -> SetGuidance ("Component of plane normal.");
92 fpCommand->SetParameter(parameter);
93}
94
96 delete fpCommand;
97}
98
100 return "";
101}
102
104
106
107 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
108 if (!viewer) {
109 if (verbosity >= G4VisManager::errors) {
110 G4cerr <<
111 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
112 << G4endl;
113 }
114 return;
115 }
116
117 G4double x, y, z, nx, ny, nz;
118 G4String unit;
119 std::istringstream is (newValue);
120 is >> x >> y >> z >> unit >> nx >> ny >> nz;
122 x *= F; y *= F; z *= F;
123
124 G4ViewParameters vp = viewer->GetViewParameters();
125 vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
126 if (verbosity >= G4VisManager::confirmations) {
127 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
128 const G4Planes& cutaways = vp.GetCutawayPlanes();
129 for (size_t i = 0; i < cutaways.size(); ++i)
130 G4cout << "\n " << i << ": " << cutaways[i];
131 G4cout << G4endl;
132 }
133
134 SetViewParameters(viewer, vp);
135}
136
138
140 G4bool omitable;
141 fpCommandCentreAndZoomInOn = new G4UIcommand ("/vis/viewer/centreAndZoomInOn", this);
143 ("Centre and zoom in on the given physical volume.");
145 ("The names of all volumes in all worlds are matched against pv-name. If"
146 "\ncopy-no is supplied, it matches the copy number too. If pv-name is of the"
147 "\nform \"/regexp/\", where regexp is a regular expression (see C++ regex),"
148 "\nthe match uses the usual rules of regular expression matching."
149 "\nOtherwise an exact match is required."
150 "\nFor example, \"/Shap/\" matches \"Shape1\" and \"Shape2\".");
152 ("It may help to see a textual representation of the geometry hierarchy of"
153 "\nthe worlds. Try \"/vis/drawTree [worlds]\" or one of the driver/browser"
154 "\ncombinations that have the required functionality, e.g., HepRepFile.");
156 ("If there are more than one matching physical volumes they will all be"
157 "\nincluded. If this is not what you want, and what you want is to centre on a"
158 "\nparticular touchable, then select the touchable (\"/vis/set/touchable\") and"
159 "\nuse \"/vis/touchable/centreOn\". (You may need \"/vis/touchable/findPath\".)");
160 G4UIparameter* parameter;
161 parameter = new G4UIparameter("pv-name",'s',omitable = false);
162 parameter->SetGuidance ("Physical volume name.");
164 parameter = new G4UIparameter("copy-no",'i',omitable = true);
165 parameter->SetDefaultValue (-1);
166 parameter->SetGuidance ("Copy number. -1 means any or all copy numbers");
168
169 fpCommandCentreOn = new G4UIcommand ("/vis/viewer/centreOn", this);
170 fpCommandCentreOn->SetGuidance ("Centre the view on the given physical volume.");
171 // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
173 // Pick up parameters from /vis/viewer/centreAndZoomInOn
175}
176
179 delete fpCommandCentreOn;
180}
181
183 return "";
184}
185
187
189 G4bool warn = verbosity >= G4VisManager::warnings;
190
191 G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
192 if (!currentViewer) {
193 if (verbosity >= G4VisManager::errors) {
194 G4cerr <<
195 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
196 << G4endl;
197 }
198 return;
199 }
200
201 G4String pvName;
202 G4int copyNo;
203 std::istringstream is (newValue);
204 is >> pvName >> copyNo;
205
206 // Find physical volumes
207 G4TransportationManager* transportationManager =
209 size_t nWorlds = transportationManager->GetNoWorlds();
210 std::vector<G4PhysicalVolumesSearchScene::Findings> findingsVector;
211 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
212 transportationManager->GetWorldsIterator();
213 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
214 G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth.
215 G4ModelingParameters mp; // Default - no culling.
216 searchModel.SetModelingParameters (&mp);
217 // Find all instances at any position in the tree
218 G4PhysicalVolumesSearchScene searchScene (&searchModel, pvName, copyNo);
219 searchModel.DescribeYourselfTo (searchScene); // Initiate search.
220 for (const auto& findings: searchScene.GetFindings()) {
221 findingsVector.push_back(findings);
222 }
223 }
224
225 if (findingsVector.empty()) {
226 if (verbosity >= G4VisManager::warnings) {
227 G4cerr
228 << "WARNING: Volume \"" << pvName << "\" ";
229 if (copyNo > 0) {
230 G4cerr << "copy number " << copyNo;
231 }
232 G4cerr << " not found." << G4endl;
233 }
234 return;
235 }
236
237 // Use a temporary scene in order to find vis extent
238 G4Scene tempScene("Centre Scene");
239 for (const auto& findings: findingsVector) {
240 // To handle paramaterisations we have to set the copy number
241 findings.fpFoundPV->SetCopyNo(findings.fFoundPVCopyNo);
242 // Create a temporary physical volume model.
243 // They have to be created on the heap because they have
244 // to hang about long enough to be conflated.
246 (findings.fpFoundPV,
247 0, // Only interested in top volume
248 findings.fFoundObjectTransformation,
249 0, // No modelling parameters (these are set later by the scene handler).
250 true, // Use full extent
251 findings.fFoundBasePVPath);
252 // ...and add it to the scene.
253 G4bool successful = tempScene.AddRunDurationModel(tempPVModel,warn);
254 if (successful) {
255 if (verbosity >= G4VisManager::confirmations) {
256 G4cout << "\"" << findings.fpFoundPV->GetName()
257 << "\", copy no. " << findings.fFoundPVCopyNo
258 << ",\n found in searched volume \""
259 << findings.fpSearchPV->GetName()
260 << "\" at depth " << findings.fFoundDepth
261 << ",\n base path: \"" << findings.fFoundBasePVPath
262 << ",\n has been added to temporary scene \"" << tempScene.GetName() << "\"."
263 << G4endl;
264 }
265 }
266 }
267 // Delete temporary physical volume models
268 for (const auto& sceneModel: tempScene.GetRunDurationModelList()) {
269 delete sceneModel.fpModel;
270 }
271
272 // Relevant results
273 const G4VisExtent& newExtent = tempScene.GetExtent();
274 const G4ThreeVector& newTargetPoint = newExtent.GetExtentCentre();
275
276 G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
277 G4ViewParameters saveVP = currentViewer->GetViewParameters();
278 G4ViewParameters newVP = saveVP;
279 if (command == fpCommandCentreAndZoomInOn) {
280 // Calculate the new zoom factor
281 const G4double zoomFactor
282 = currentScene->GetExtent().GetExtentRadius()/newExtent.GetExtentRadius();
283 newVP.SetZoomFactor(zoomFactor);
284 }
285 // Change the target point
286 const G4Point3D& standardTargetPoint = currentScene->GetStandardTargetPoint();
287 newVP.SetCurrentTargetPoint(newTargetPoint - standardTargetPoint);
288 // Interpolate
289 InterpolateToNewView(currentViewer, saveVP, newVP);
290
291 if (verbosity >= G4VisManager::confirmations) {
292 G4cout
293 << "Viewer \"" << currentViewer->GetName()
294 << "\" centred ";
296 G4cout << "and zoomed in";
297 }
298 G4cout << " on physical volume(s) \"" << pvName << '\"'
299 << G4endl;
300 }
301
302 SetViewParameters(currentViewer, newVP);
303}
304
306
308 G4bool omitable;
309 fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
310 fpCommand -> SetGuidance("Change cutaway plane.");
311 G4UIparameter* parameter;
312 parameter = new G4UIparameter("index",'i',omitable = false);
313 parameter -> SetGuidance ("Index of plane: 0, 1, 2.");
314 fpCommand->SetParameter(parameter);
315 parameter = new G4UIparameter("x",'d',omitable = true);
316 parameter -> SetDefaultValue (0);
317 parameter -> SetGuidance ("Coordinate of point on the plane.");
318 fpCommand->SetParameter(parameter);
319 parameter = new G4UIparameter("y",'d',omitable = true);
320 parameter -> SetDefaultValue (0);
321 parameter -> SetGuidance ("Coordinate of point on the plane.");
322 fpCommand->SetParameter(parameter);
323 parameter = new G4UIparameter("z",'d',omitable = true);
324 parameter -> SetDefaultValue (0);
325 parameter -> SetGuidance ("Coordinate of point on the plane.");
326 fpCommand->SetParameter(parameter);
327 parameter = new G4UIparameter("unit",'s',omitable = true);
328 parameter -> SetDefaultValue ("m");
329 parameter -> SetGuidance ("Unit of point on the plane.");
330 fpCommand->SetParameter(parameter);
331 parameter = new G4UIparameter("nx",'d',omitable = true);
332 parameter -> SetDefaultValue (1);
333 parameter -> SetGuidance ("Component of plane normal.");
334 fpCommand->SetParameter(parameter);
335 parameter = new G4UIparameter("ny",'d',omitable = true);
336 parameter -> SetDefaultValue (0);
337 parameter -> SetGuidance ("Component of plane normal.");
338 fpCommand->SetParameter(parameter);
339 parameter = new G4UIparameter("nz",'d',omitable = true);
340 parameter -> SetDefaultValue (0);
341 parameter -> SetGuidance ("Component of plane normal.");
342 fpCommand->SetParameter(parameter);
343}
344
346 delete fpCommand;
347}
348
350 return "";
351}
352
354
356
357 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
358 if (!viewer) {
359 if (verbosity >= G4VisManager::errors) {
360 G4cerr <<
361 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
362 << G4endl;
363 }
364 return;
365 }
366
367 size_t index;
368 G4double x, y, z, nx, ny, nz;
369 G4String unit;
370 std::istringstream is (newValue);
371 is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
373 x *= F; y *= F; z *= F;
374
375 G4ViewParameters vp = viewer->GetViewParameters();
376 vp.ChangeCutawayPlane(index,
377 G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
378 if (verbosity >= G4VisManager::confirmations) {
379 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
380 const G4Planes& cutaways = vp.GetCutawayPlanes();
381 for (size_t i = 0; i < cutaways.size(); ++i)
382 G4cout << "\n " << i << ": " << cutaways[i];
383 G4cout << G4endl;
384 }
385
386 SetViewParameters(viewer, vp);
387}
388
390
392 G4bool omitable, currentAsDefault;
393 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
394 fpCommand -> SetGuidance ("Clears viewer.");
395 fpCommand -> SetGuidance
396 ("By default, clears current viewer. Specified viewer becomes current."
397 "\n\"/vis/viewer/list\" to see possible viewer names.");
398 fpCommand -> SetParameterName ("viewer-name",
399 omitable = true,
400 currentAsDefault = true);
401}
402
404 delete fpCommand;
405}
406
408 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
409 return viewer ? viewer -> GetName () : G4String("none");
410}
411
413
415
416 G4String& clearName = newValue;
417 G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
418 if (!viewer) {
419 if (verbosity >= G4VisManager::errors) {
420 G4cerr << "ERROR: Viewer \"" << clearName
421 << "\" not found - \"/vis/viewer/list\" to see possibilities."
422 << G4endl;
423 }
424 return;
425 }
426
427 viewer->SetView();
428 viewer->ClearView();
429 viewer->FinishView();
430 if (verbosity >= G4VisManager::confirmations) {
431 G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
432 }
433
434}
435
437
440 ("/vis/viewer/clearCutawayPlanes", this);
441 fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
442}
443
445 delete fpCommand;
446}
447
449 return "";
450}
451
453
455
456 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
457 if (!viewer) {
458 if (verbosity >= G4VisManager::errors) {
459 G4cerr <<
460 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
461 << G4endl;
462 }
463 return;
464 }
465
466 G4ViewParameters vp = viewer->GetViewParameters();
468 if (verbosity >= G4VisManager::confirmations) {
469 G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
470 << "\" now cleared." << G4endl;
471 }
472
473 SetViewParameters(viewer, vp);
474}
475
477
479 G4bool omitable, currentAsDefault;
480 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
481 fpCommand -> SetGuidance ("Clears transients from viewer.");
482 fpCommand -> SetGuidance
483 ("By default, operates on current viewer. Specified viewer becomes current."
484 "\n\"/vis/viewer/list\" to see possible viewer names.");
485 fpCommand -> SetParameterName ("viewer-name",
486 omitable = true,
487 currentAsDefault = true);
488}
489
491 delete fpCommand;
492}
493
495 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
496 return viewer ? viewer -> GetName () : G4String("none");
497}
498
500
502
503 G4String& clearName = newValue;
504 G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
505 if (!viewer) {
506 if (verbosity >= G4VisManager::errors) {
507 G4cerr << "ERROR: Viewer \"" << clearName
508 << "\" not found - \"/vis/viewer/list\" to see possibilities."
509 << G4endl;
510 }
511 return;
512 }
513
514 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
515 sceneHandler->SetMarkForClearingTransientStore(false);
517 sceneHandler->ClearTransientStore();
518 if (verbosity >= G4VisManager::confirmations) {
519 G4cout << "Viewer \"" << clearName << "\" cleared of transients."
520 << G4endl;
521 }
522
523}
524
526
529 ("/vis/viewer/clearVisAttributesModifiers", this);
530 fpCommand -> SetGuidance ("Clear vis attribute modifiers of current viewer.");
531 fpCommand -> SetGuidance ("(These are used for touchables, etc.)");
532}
533
535 delete fpCommand;
536}
537
539 return "";
540}
541
543
545
546 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
547 if (!viewer) {
548 if (verbosity >= G4VisManager::errors) {
549 G4cerr <<
550 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
551 << G4endl;
552 }
553 return;
554 }
555
556 G4ViewParameters vp = viewer->GetViewParameters();
558 if (verbosity >= G4VisManager::confirmations) {
559 G4cout << "Vis attributes modifiers for viewer \"" << viewer->GetName()
560 << "\" now cleared." << G4endl;
561 }
562
563 SetViewParameters(viewer, vp);
564}
565
567
569 G4bool omitable;
570 fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
571 fpCommand -> SetGuidance ("Clones viewer.");
572 fpCommand -> SetGuidance
573 ("By default, clones current viewer. Clone becomes current."
574 "\nClone name, if not provided, is derived from the original name."
575 "\n\"/vis/viewer/list\" to see possible viewer names.");
576 G4UIparameter* parameter;
577 parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
578 parameter -> SetCurrentAsDefault (true);
579 fpCommand -> SetParameter (parameter);
580 parameter = new G4UIparameter ("clone-name", 's', omitable = true);
581 parameter -> SetDefaultValue ("none");
582 fpCommand -> SetParameter (parameter);
583}
584
586 delete fpCommand;
587}
588
590 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
591 G4String originalName = viewer ? viewer -> GetName () : G4String("none");
592 return "\"" + originalName + "\"";
593}
594
596
598
599 G4String originalName, cloneName;
600 std::istringstream is (newValue);
601
602 // Need to handle the possibility that the names contain embedded
603 // blanks within quotation marks...
604 char c = ' ';
605 while (is.get(c) && c == ' '){}
606 if (c == '"') {
607 while (is.get(c) && c != '"') {originalName += c;}
608 }
609 else {
610 originalName += c;
611 while (is.get(c) && c != ' ') {originalName += c;}
612 }
613 G4StrUtil::strip(originalName, ' ');
614 G4StrUtil::strip(originalName, '"');
615
616 G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
617 if (!originalViewer) {
618 if (verbosity >= G4VisManager::errors) {
619 G4cerr << "ERROR: Viewer \"" << originalName
620 << "\" not found - \"/vis/viewer/list\" to see possibilities."
621 << G4endl;
622 }
623 return;
624 }
625 originalName = originalViewer->GetName(); // Ensures long name.
626
627 while (is.get(c) && c == ' '){}
628 if (c == '"') {
629 while (is.get(c) && c != '"') {cloneName += c;}
630 }
631 else {
632 cloneName += c;
633 while (is.get(c) && c != ' ') {cloneName += c;}
634 }
635 G4StrUtil::strip(cloneName, ' ');
636 G4StrUtil::strip(cloneName, '"');
637
638 G4bool errorWhileNaming = false;
639 if (cloneName == "none") {
640 G4int subID = 0;
641 do {
642 cloneName = originalName;
643 std::ostringstream oss;
644 oss << '-' << subID++;
645 G4String::size_type lastDashPosition, nextSpacePosition;
646 if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos &&
647 (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
648 G4String::npos) {
649 cloneName.insert(nextSpacePosition, oss.str());
650 } else {
651 G4String::size_type spacePosition = cloneName.find(' ');
652 if (spacePosition != G4String::npos)
653 cloneName.insert(spacePosition, oss.str());
654 else
655 errorWhileNaming = true;
656 }
657 } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName));
658 }
659
660 if (errorWhileNaming) {
661 if (verbosity >= G4VisManager::errors) {
662 G4cerr << "ERROR: While naming clone viewer \"" << cloneName
663 << "\"."
664 << G4endl;
665 }
666 return;
667 }
668
669 if (fpVisManager -> GetViewer (cloneName)) {
670 if (verbosity >= G4VisManager::errors) {
671 G4cerr << "ERROR: Putative clone viewer \"" << cloneName
672 << "\" already exists."
673 << G4endl;
674 }
675 return;
676 }
677
678 G4String windowSizeHint =
679 originalViewer->GetViewParameters().GetXGeometryString();
680
682 G4int keepVerbose = UImanager->GetVerboseLevel();
683 G4int newVerbose(0);
684 if (keepVerbose >= 2 ||
686 newVerbose = 2;
687 UImanager->SetVerboseLevel(newVerbose);
688 UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
689 UImanager->ApplyCommand
690 (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
691 UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
692 UImanager->SetVerboseLevel(keepVerbose);
693
694 if (verbosity >= G4VisManager::confirmations) {
695 G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
696 G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
697 }
698}
699
701
703 G4bool omitable;
704 fpCommand = new G4UIcommand ("/vis/viewer/colourByDensity", this);
705 fpCommand -> SetGuidance
706 ("If a volume has no vis attributes, colour it by density.");
707 fpCommand -> SetGuidance
708 ("Provide algorithm number, e.g., \"1\" (or \"0\" to switch off)."
709 "\nThen a unit of density, e.g., \"g/cm3\"."
710 "\nThen parameters for the algorithm assumed to be densities in that unit.");
711 fpCommand -> SetGuidance
712 ("Algorithm 1: Simple algorithm takes 3 parameters: d0, d1 and d2."
713 "\n Volumes with density < d0 are invisible."
714 "\n Volumes with d0 <= density < d1 have colour on range red->green."
715 "\n Volumes with d1 <= density < d2 have colour on range green->blue."
716 "\n Volumes with density > d2 are blue.");
717 G4UIparameter* parameter;
718 parameter = new G4UIparameter("n",'i',omitable = true);
719 parameter -> SetGuidance ("Algorithm number (or \"0\" to switch off).");
720 parameter -> SetDefaultValue (1);
721 fpCommand->SetParameter(parameter);
722 parameter = new G4UIparameter("unit",'s',omitable = true);
723 parameter -> SetGuidance ("Unit of following densities, e.g., \"g/cm3\".");
724 parameter -> SetDefaultValue ("g/cm3");
725 fpCommand->SetParameter(parameter);
726 parameter = new G4UIparameter("d0",'d',omitable = true);
727 parameter -> SetGuidance ("Density parameter 0");
728 parameter -> SetDefaultValue (0.5);
729 fpCommand->SetParameter(parameter);
730 parameter = new G4UIparameter("d1",'d',omitable = true);
731 parameter -> SetGuidance ("Density parameter 1");
732 parameter -> SetDefaultValue (3.0);
733 fpCommand->SetParameter(parameter);
734 parameter = new G4UIparameter("d2",'d',omitable = true);
735 parameter -> SetGuidance ("Density parameter 2.");
736 parameter -> SetDefaultValue (10.0);
737 fpCommand->SetParameter(parameter);
738}
739
741 delete fpCommand;
742}
743
745 return "";
746}
747
749
751
752 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
753 if (!viewer) {
754 if (verbosity >= G4VisManager::errors) {
755 G4cerr <<
756 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
757 << G4endl;
758 }
759 return;
760 }
761 G4ViewParameters vp = viewer->GetViewParameters();
762
763 G4int algorithmNumber;
764 G4double d0, d1, d2;
765 G4String unit;
766 std::istringstream is (newValue);
767 is >> algorithmNumber >> unit >> d0 >> d1 >> d2;
768
769 if (algorithmNumber < 0 || algorithmNumber > 1) {
770 if (verbosity >= G4VisManager::errors) {
771 G4cerr <<
772 "ERROR: Unrecognised algorithm number: " << algorithmNumber
773 << G4endl;
774 }
775 return;
776 }
777
778 std::vector<G4double> parameters;
779 if (algorithmNumber > 0) {
780 const G4String where = "G4VisCommandViewerColourByDensity::SetNewValue";
781 G4double valueOfUnit;
782 // "Volumic Mass" is Michel's phrase for "Density"
783 if (ProvideValueOfUnit(where,unit,"Volumic Mass",valueOfUnit)) {
784 // Successful outcome of unit search
785 d0 *= valueOfUnit; d1 *= valueOfUnit; d2 *= valueOfUnit;
786 } else {
787 if (verbosity >= G4VisManager::errors) {
788 G4cerr <<
789 "ERROR: Unrecognised or inappropriate unit: " << unit
790 << G4endl;
791 }
792 return;
793 }
794 parameters.push_back(d0);
795 parameters.push_back(d1);
796 parameters.push_back(d2);
797 }
798 vp.SetCBDAlgorithmNumber(algorithmNumber);
799 vp.SetCBDParameters(parameters);
800
801 if (verbosity >= G4VisManager::confirmations) {
802 if (vp.GetCBDAlgorithmNumber() == 0) {
803 G4cout << "Colour by density deactivated" << G4endl;
804 } else {
805 G4cout << "Colour by density algorithm " << vp.GetCBDAlgorithmNumber()
806 << " selected for viewer \"" << viewer->GetName()
807 << "\n Parameters:";
808 for (auto p: vp.GetCBDParameters()) {
809 G4cout << ' ' << G4BestUnit(p,"Volumic Mass");
810 }
811 G4cout << G4endl;
812 }
813 }
814
815 SetViewParameters(viewer, vp);
816}
817
819
821 G4bool omitable;
822 fpCommand = new G4UIcmdWithAString ("/vis/viewer/copyViewFrom", this);
823 fpCommand -> SetGuidance
824 ("Copy the camera-specific parameters from the specified viewer.");
825 fpCommand -> SetGuidance
826 ("Note: To copy ALL view parameters, including scene modifications,"
827 "\nuse \"/vis/viewer/set/all\"");
828 fpCommand -> SetParameterName ("from-viewer-name", omitable = false);
829}
830
832 delete fpCommand;
833}
834
836 return "";
837}
838
840
842
843 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
844 if (!currentViewer) {
845 if (verbosity >= G4VisManager::errors) {
846 G4cerr <<
847 "ERROR: G4VisCommandsViewerCopyViewFrom::SetNewValue: no current viewer."
848 << G4endl;
849 }
850 return;
851 }
852
853 const G4String& fromViewerName = newValue;
854 G4VViewer* fromViewer = fpVisManager -> GetViewer (fromViewerName);
855 if (!fromViewer) {
856 if (verbosity >= G4VisManager::errors) {
857 G4cerr << "ERROR: Viewer \"" << fromViewerName
858 << "\" not found - \"/vis/viewer/list\" to see possibilities."
859 << G4endl;
860 }
861 return;
862 }
863
864 if (fromViewer == currentViewer) {
865 if (verbosity >= G4VisManager::warnings) {
866 G4cout <<
867 "WARNING: G4VisCommandsViewerSet::SetNewValue:"
868 "\n from-viewer and current viewer are identical."
869 << G4endl;
870 }
871 return;
872 }
873
874 // Copy camera-specific view parameters
875 G4ViewParameters vp = currentViewer->GetViewParameters();
876 CopyCameraParameters(vp, fromViewer->GetViewParameters());
877 SetViewParameters(currentViewer, vp);
878
879 if (verbosity >= G4VisManager::confirmations) {
880 G4cout << "Camera parameters of viewer \"" << currentViewer->GetName()
881 << "\"\n set to those of viewer \"" << fromViewer->GetName()
882 << "\"."
883 << G4endl;
884 }
885}
886
888
890 G4bool omitable;
891 fpCommand = new G4UIcommand ("/vis/viewer/create", this);
892 fpCommand -> SetGuidance
893 ("Creates a viewer for the specified scene handler.");
894 fpCommand -> SetGuidance
895 ("Default scene handler is the current scene handler. Invents a name"
896 "\nif not supplied. (Note: the system adds information to the name"
897 "\nfor identification - only the characters up to the first blank are"
898 "\nused for removing, selecting, etc.) This scene handler and viewer"
899 "\nbecome current.");
900 G4UIparameter* parameter;
901 parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
902 parameter -> SetCurrentAsDefault (true);
903 fpCommand -> SetParameter (parameter);
904 parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
905 parameter -> SetCurrentAsDefault (true);
906 fpCommand -> SetParameter (parameter);
907 parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
908 parameter->SetGuidance
909 ("integer (pixels) for square window placed by window manager or"
910 " X-Windows-type geometry string, e.g. 600x600-100+100");
911 parameter->SetDefaultValue("600");
912 fpCommand -> SetParameter (parameter);
913}
914
916 delete fpCommand;
917}
918
920 std::ostringstream oss;
921 G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
922 oss << "viewer-" << fId << " (";
923 if (sceneHandler) {
924 oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
925 }
926 else {
927 oss << "no_scene_handlers";
928 }
929 oss << ")";
930 return oss.str();
931}
932
934 G4String currentValue;
935 G4VSceneHandler* currentSceneHandler =
936 fpVisManager -> GetCurrentSceneHandler ();
937 if (currentSceneHandler) {
938 currentValue = currentSceneHandler -> GetName ();
939 }
940 else {
941 currentValue = "none";
942 }
943 currentValue += ' ';
944 currentValue += '"';
945 currentValue += NextName ();
946 currentValue += '"';
947
948 currentValue += " 600"; // Default number of pixels for window size hint.
949
950 return currentValue;
951}
952
954
956
957 G4String sceneHandlerName, newName;
958 G4String windowSizeHintString;
959 std::istringstream is (newValue);
960 is >> sceneHandlerName;
961
962 // Now need to handle the possibility that the second string
963 // contains embedded blanks within quotation marks...
964 char c = ' ';
965 while (is.get(c) && c == ' '){}
966 if (c == '"') {
967 while (is.get(c) && c != '"') {newName += c;}
968 }
969 else {
970 newName += c;
971 while (is.get(c) && c != ' ') {newName += c;}
972 }
973 G4StrUtil::strip(newName, ' ');
974 G4StrUtil::strip(newName, '"');
975
976 // Now get window size hint...
977 is >> windowSizeHintString;
978
979 const G4SceneHandlerList& sceneHandlerList =
980 fpVisManager -> GetAvailableSceneHandlers ();
981 G4int nHandlers = sceneHandlerList.size ();
982 if (nHandlers <= 0) {
984 ed <<
985 "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
986 "\n Create a scene handler with \"/vis/sceneHandler/create\"";
987 command->CommandFailed(ed);
988 return;
989 }
990
991 G4int iHandler;
992 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
993 if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
994 }
995
996 if (iHandler < 0 || iHandler >= nHandlers) {
997 // Invalid command line argument or none.
998 // This shouldn't happen!!!!!!
1000 ed <<
1001 "G4VisCommandViewerCreate::SetNewValue: invalid scene handler specified.";
1002 command->CommandFailed(ed);
1003 return;
1004 }
1005
1006 // Valid index. Set current scene handler and graphics system in
1007 // preparation for creating viewer.
1008 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
1009 if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
1010 fpVisManager -> SetCurrentSceneHandler (sceneHandler);
1011 }
1012
1013 // Now deal with name of viewer.
1014 G4String nextName = NextName ();
1015 if (newName == "") {
1016 newName = nextName;
1017 }
1018 if (newName == nextName) fId++;
1019 G4String newShortName = fpVisManager -> ViewerShortName (newName);
1020
1021 for (G4int ih = 0; ih < nHandlers; ih++) {
1022 G4VSceneHandler* sh = sceneHandlerList [ih];
1023 const G4ViewerList& viewerList = sh -> GetViewerList ();
1024 for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1025 if (viewerList [iViewer] -> GetShortName () == newShortName ) {
1027 ed <<
1028 "ERROR: Viewer \"" << newShortName << "\" already exists.";
1029 command->CommandFailed(ed);
1030 return;
1031 }
1032 }
1033 }
1034
1035 // If there was an existing viewer, use its view parameters
1036 if (fThereWasAViewer) {
1037 // OK, we're going to use its view parameters below
1038 } else {
1039 // There wasn't one...but if there now is...
1041 fThereWasAViewer = true;
1043 }
1044 }
1045
1046 // WindowSizeHint and XGeometryString are picked up from the vis
1047 // manager in the G4VViewer constructor. In G4VisManager, after Viewer
1048 // creation, we will store theses parameters in G4ViewParameters.
1049
1050 fpVisManager -> CreateViewer (newName,windowSizeHintString);
1051
1052 G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
1053
1054 if (newViewer && newViewer -> GetName () == newName) {
1055 if (fThereWasAViewer) {
1056 G4ViewParameters vp = newViewer->GetViewParameters();
1059 }
1060 if (verbosity >= G4VisManager::confirmations) {
1061 G4cout << "New viewer \"" << newName << "\" created." << G4endl;
1062 }
1063 }
1064 else {
1066 if (newViewer) {
1067 ed << "ERROR: New viewer doesn\'t match!!! Curious!!";
1068 } else {
1069 ed << "WARNING: No viewer created.";
1070 }
1071 command->CommandFailed(ed);
1072 return;
1073 }
1074 // Refresh if appropriate...
1075 if (newViewer) {
1076 if (newViewer->GetViewParameters().IsAutoRefresh()) {
1077 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
1078 }
1079 else {
1080 if (verbosity >= G4VisManager::warnings) {
1081 G4cout << "Issue /vis/viewer/refresh or flush to see effect."
1082 << G4endl;
1083 }
1084 }
1085 }
1086}
1087
1089
1091 fDollyIncrement (0.),
1092 fDollyTo (0.)
1093{
1094 G4bool omitable, currentAsDefault;
1095
1097 ("/vis/viewer/dolly", this);
1098 fpCommandDolly -> SetGuidance
1099 ("Incremental dolly.");
1100 fpCommandDolly -> SetGuidance
1101 ("Moves the camera incrementally towards target point.");
1102 fpCommandDolly -> SetParameterName("increment",
1103 omitable=true,
1104 currentAsDefault=true);
1105 fpCommandDolly -> SetDefaultUnit("m");
1106
1108 ("/vis/viewer/dollyTo", this);
1109 fpCommandDollyTo -> SetGuidance
1110 ("Dolly to specific coordinate.");
1111 fpCommandDollyTo -> SetGuidance
1112 ("Places the camera towards target point relative to standard camera point.");
1113 fpCommandDollyTo -> SetParameterName("distance",
1114 omitable=true,
1115 currentAsDefault=true);
1116 fpCommandDollyTo -> SetDefaultUnit("m");
1117}
1118
1120 delete fpCommandDolly;
1121 delete fpCommandDollyTo;
1122}
1123
1125 G4String currentValue;
1126 if (command == fpCommandDolly) {
1127 currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
1128 }
1129 else if (command == fpCommandDollyTo) {
1130 currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
1131 }
1132 return currentValue;
1133}
1134
1136 G4String newValue) {
1137
1138
1140
1141 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1142 if (!currentViewer) {
1143 if (verbosity >= G4VisManager::errors) {
1144 G4cerr <<
1145 "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
1146 << G4endl;
1147 }
1148 return;
1149 }
1150
1151 G4ViewParameters vp = currentViewer->GetViewParameters();
1152
1153 if (command == fpCommandDolly) {
1156 }
1157 else if (command == fpCommandDollyTo) {
1159 vp.SetDolly(fDollyTo);
1160 }
1161
1162 if (verbosity >= G4VisManager::confirmations) {
1163 G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
1164 }
1165
1166 SetViewParameters(currentViewer, vp);
1167}
1168
1170
1172 G4bool omitable, currentAsDefault;
1173 fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
1174 fpCommand -> SetGuidance
1175 ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
1176 fpCommand -> SetGuidance
1177 ("Useful for refreshing and initiating post-processing for graphics"
1178 "\nsystems which need post-processing. By default, acts on current"
1179 "\nviewer. \"/vis/viewer/list\" to see possible viewers. Viewer"
1180 "\nbecomes current.");
1181 fpCommand -> SetParameterName ("viewer-name",
1182 omitable = true,
1183 currentAsDefault = true);
1184}
1185
1187 delete fpCommand;
1188}
1189
1191(G4UIcommand*) {
1192 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1193 return viewer ? viewer -> GetName () : G4String("none");
1194}
1195
1197
1199
1200 G4String& flushName = newValue;
1201 G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
1202 if (!viewer) {
1203 if (verbosity >= G4VisManager::errors) {
1204 G4cerr << "ERROR: Viewer \"" << flushName << "\"" <<
1205 " not found - \"/vis/viewer/list\"\n to see possibilities."
1206 << G4endl;
1207 }
1208 return;
1209 }
1210
1212 G4int keepVerbose = ui->GetVerboseLevel();
1213 G4int newVerbose(0);
1214 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
1215 newVerbose = 2;
1216 ui->SetVerboseLevel(newVerbose);
1217 ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
1218 ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
1219 ui->SetVerboseLevel(keepVerbose);
1220 if (verbosity >= G4VisManager::confirmations) {
1221 G4cout << "Viewer \"" << viewer -> GetName () << "\""
1222 << " flushed." << G4endl;
1223 }
1224}
1225
1227
1229 G4bool omitable;
1230 fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
1231 fpCommand -> SetGuidance
1232 ("Interpolate views defined by the first argument, which can contain "
1233 "Unix-shell-style pattern matching characters such as '*', '?' and '[' "
1234 "- see \"man sh\" and look for \"Pattern Matching\". The contents "
1235 "of each file are assumed to be \"/vis/viewer\" commands "
1236 "that specify a particular view. The files are processed in alphanumeric "
1237 "order of filename. The files may be written by hand or produced by the "
1238 "\"/vis/viewer/save\" command.");
1239 fpCommand -> SetGuidance
1240 ("The default is to search the working directory for files with a .g4view "
1241 "extension. Another procedure is to assemble view files in a subdirectory, "
1242 "e.g., \"myviews\"; then they can be interpolated with\n"
1243 "\"/vis/viewer/interpolate myviews\".");
1244 fpCommand -> SetGuidance
1245 ("To export interpolated views to file for a future possible movie, "
1246 "write \"export\" as 5th parameter (OpenGL only).");
1247 G4UIparameter* parameter;
1248 parameter = new G4UIparameter("pattern", 's', omitable = true);
1249 parameter -> SetGuidance("Pattern that defines the view files.");
1250 parameter -> SetDefaultValue("*.g4view");
1251 fpCommand -> SetParameter(parameter);
1252 parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
1253 parameter -> SetGuidance ("Number of interpolation points per interval.");
1254 parameter -> SetDefaultValue(50);
1255 fpCommand -> SetParameter(parameter);
1256 parameter = new G4UIparameter("wait-time", 's', omitable = true);
1257 parameter -> SetGuidance("Wait time per interpolated point");
1258 parameter -> SetDefaultValue("20.");
1259 fpCommand -> SetParameter(parameter);
1260 parameter = new G4UIparameter("time-unit", 's', omitable = true);
1261 parameter -> SetDefaultValue("millisecond");
1262 fpCommand -> SetParameter (parameter);
1263 parameter = new G4UIparameter("export", 's', omitable = true);
1264 parameter -> SetDefaultValue("no");
1265 fpCommand -> SetParameter (parameter);
1266}
1267
1269 delete fpCommand;
1270}
1271
1273 return "";
1274}
1275
1277
1279
1280 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1281 if (!currentViewer) {
1282 if (verbosity >= G4VisManager::errors) {
1283 G4cerr <<
1284 "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
1285 << G4endl;
1286 }
1287 return;
1288 }
1289
1290 G4String pattern;
1291 G4int nInterpolationPoints;
1292 G4String waitTimePerPointString;
1293 G4String timeUnit;
1294 G4String exportString;
1295
1296 std::istringstream iss (newValue);
1297 iss
1298 >> pattern
1299 >> nInterpolationPoints
1300 >> waitTimePerPointString
1301 >> timeUnit
1302 >> exportString;
1303 G4String waitTimePerPointDimString(waitTimePerPointString + ' ' + timeUnit);
1304 const G4double waitTimePerPoint =
1305 G4UIcommand::ConvertToDimensionedDouble(waitTimePerPointDimString.c_str());
1306 G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
1307 if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
1308
1310
1311 // Save current view parameters
1312 G4ViewParameters saveVP = currentViewer->GetViewParameters();
1313
1314 // Save current verbosities
1316 G4int keepUIVerbosity = uiManager->GetVerboseLevel();
1317
1318 // Set verbosities for this operation
1320 uiManager->SetVerboseLevel(0);
1321
1322 // Switch off auto-refresh while we read in the view files (it will be
1323 // restored later). Note: the view files do not set auto-refresh.
1324 G4ViewParameters non_auto = saveVP;
1325 non_auto.SetAutoRefresh(false);
1326 currentViewer->SetViewParameters(non_auto);
1327
1328 const G4int safety = 99;
1329 G4int safetyCount = 0;
1330 G4fs::path pathPattern = pattern.c_str();
1331
1332 // Parent path - add "./" for empty directory
1333 G4String parentPathString
1334 (pathPattern.parent_path().string().length() ?
1335 pathPattern.parent_path().string() :
1336 std::string("./"));
1337 G4fs::path parentPath = parentPathString.c_str();
1338
1339 // Fill selected paths
1340 std::set<G4fs::path> paths; // Use std::set to ensure order
1341
1342 if (G4fs::is_directory(pathPattern)) {
1343
1344 // The user has specified a directory. Find all files.
1345 for (const auto& path: G4fs::directory_iterator(pathPattern)) {
1346 if (safetyCount++ >= safety) break;
1347 paths.insert(path);
1348 }
1349
1350 } else {
1351
1352 // Assume user has specified a Unix "glob" pattern in leaf
1353 // Default pattern is *.g4view, which translates to ^.*\\.g4view
1354 // Convert pattern into a regexp
1355 G4String regexp_pattern("^");
1356 for (size_t i = 0; i < pattern.length(); ++i) {
1357 if (pattern[i] == '.') {
1358 regexp_pattern += "\\.";
1359 } else if (pattern[i] == '*') {
1360 regexp_pattern += ".*";
1361 } else if (pattern[i] == '?') {
1362 regexp_pattern += "(.{1,1})";
1363 } else {
1364 regexp_pattern += pattern[i];
1365 }
1366 }
1367 std::regex regexp(regexp_pattern, std::regex_constants::basic | std::regex_constants::icase);
1368
1369 for (const auto& path: G4fs::directory_iterator(parentPath)) {
1370 const auto& pathname = path.path().relative_path().string();
1371 if (std::regex_match(pathname, regexp)) {
1372 if (safetyCount++ >= safety) break;
1373 paths.insert(path);
1374 }
1375 }
1376 }
1377
1378 if (safetyCount > safety) {
1379 if (verbosity >= G4VisManager::errors) {
1380 G4cerr <<
1381 "/vis/viewer/interpolate:"
1382 "\n the number of way points has been limited to the maximum currently allowed: "
1383 << safety << G4endl;
1384 }
1385 }
1386
1387 // Fill view vector of way points
1388 std::vector<G4ViewParameters> viewVector;
1389 for (const auto& path: paths) {
1390 uiManager->ApplyCommand("/control/execute " + path.relative_path().string());
1391 G4ViewParameters vp = currentViewer->GetViewParameters();
1392 // Set original auto-refresh status.
1393 vp.SetAutoRefresh(saveVP.IsAutoRefresh());
1394 viewVector.push_back(vp);
1395 }
1396
1398 (currentViewer,viewVector,
1399 nInterpolationPoints,waitTimePerPointmilliseconds,exportString);
1400
1401 // Restore original verbosities
1402 uiManager->SetVerboseLevel(keepUIVerbosity);
1403 fpVisManager->SetVerboseLevel(keepVisVerbosity);
1404
1405 // Restore original view parameters
1406 currentViewer->SetViewParameters(saveVP);
1407 currentViewer->RefreshView();
1408 if (verbosity >= G4VisManager::confirmations) {
1409 G4cout << "Viewer \"" << currentViewer -> GetName () << "\""
1410 << " restored." << G4endl;
1411 }
1412}
1413
1415
1417 G4bool omitable;
1418 fpCommand = new G4UIcommand ("/vis/viewer/list", this);
1419 fpCommand -> SetGuidance ("Lists viewers(s).");
1420 fpCommand -> SetGuidance
1421 ("See \"/vis/verbose\" for definition of verbosity.");
1422 G4UIparameter* parameter;
1423 parameter = new G4UIparameter("viewer-name", 's',
1424 omitable = true);
1425 parameter -> SetDefaultValue ("all");
1426 fpCommand -> SetParameter (parameter);
1427 parameter = new G4UIparameter ("verbosity", 's',
1428 omitable = true);
1429 parameter -> SetDefaultValue ("warnings");
1430 fpCommand -> SetParameter (parameter);
1431}
1432
1434 delete fpCommand;
1435}
1436
1438 return "";
1439}
1440
1442 G4String name, verbosityString;
1443 std::istringstream is (newValue);
1444 is >> name >> verbosityString;
1445 G4String shortName = fpVisManager -> ViewerShortName (name);
1446 G4VisManager::Verbosity verbosity =
1447 fpVisManager->GetVerbosityValue(verbosityString);
1448
1449 const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
1450 G4String currentViewerShortName;
1451 if (currentViewer) {
1452 currentViewerShortName = currentViewer -> GetShortName ();
1453 }
1454 else {
1455 currentViewerShortName = "none";
1456 }
1457
1458 const G4SceneHandlerList& sceneHandlerList =
1459 fpVisManager -> GetAvailableSceneHandlers ();
1460 G4int nHandlers = sceneHandlerList.size ();
1461 G4bool found = false;
1462 G4bool foundCurrent = false;
1463 for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
1464 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
1465 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
1466 G4cout
1467 << "Scene handler \"" << sceneHandler -> GetName () << "\" ("
1468 << sceneHandler->GetGraphicsSystem()->GetNickname() << ')';
1469 const G4Scene* pScene = sceneHandler -> GetScene ();
1470 if (pScene) {
1471 G4cout << ", scene \"" << pScene -> GetName () << "\"";
1472 }
1473 G4cout << ':';
1474 G4int nViewers = viewerList.size ();
1475 if (nViewers == 0) {
1476 G4cout << "\n No viewers for this scene handler." << G4endl;
1477 }
1478 else {
1479 for (int iViewer = 0; iViewer < nViewers; iViewer++) {
1480 const G4VViewer* thisViewer = viewerList [iViewer];
1481 G4String thisName = thisViewer -> GetName ();
1482 G4String thisShortName = thisViewer -> GetShortName ();
1483 if (name != "all") {
1484 if (thisShortName != shortName) continue;
1485 }
1486 found = true;
1487 G4cout << "\n ";
1488 if (thisShortName == currentViewerShortName) {
1489 foundCurrent = true;
1490 G4cout << "(current)";
1491 }
1492 else {
1493 G4cout << " ";
1494 }
1495 G4cout << " viewer \"" << thisName << "\"";
1496 if (verbosity >= G4VisManager::parameters) {
1497 G4cout << "\n " << *thisViewer;
1498 }
1499 }
1500 }
1501 G4cout << G4endl;
1502 }
1503
1504 if (!foundCurrent) {
1505 G4cout << "No valid current viewer - please create or select one."
1506 << G4endl;
1507 }
1508
1509 if (!found) {
1510 G4cout << "No viewers";
1511 if (name != "all") {
1512 G4cout << " of name \"" << name << "\"";
1513 }
1514 G4cout << " found." << G4endl;
1515 }
1516}
1517
1519
1521 fPanIncrementRight (0.),
1522 fPanIncrementUp (0.),
1523 fPanToRight (0.),
1524 fPanToUp (0.)
1525{
1526 G4bool omitable;
1527
1529 ("/vis/viewer/pan", this);
1530 fpCommandPan -> SetGuidance
1531 ("Incremental pan.");
1532 fpCommandPan -> SetGuidance
1533 ("Moves the camera incrementally right and up by these amounts (as seen"
1534 "\nfrom viewpoint direction).");
1535 G4UIparameter* parameter;
1536 parameter = new G4UIparameter("right-increment", 'd', omitable = true);
1537 parameter -> SetCurrentAsDefault (true);
1538 fpCommandPan -> SetParameter (parameter);
1539 parameter = new G4UIparameter("up-increment", 'd', omitable = true);
1540 parameter -> SetCurrentAsDefault (true);
1541 fpCommandPan -> SetParameter (parameter);
1542 parameter = new G4UIparameter ("unit", 's', omitable = true);
1543 parameter -> SetDefaultValue ("m");
1544 fpCommandPan -> SetParameter (parameter);
1545
1547 ("/vis/viewer/panTo", this);
1548 fpCommandPanTo -> SetGuidance
1549 ("Pan to specific coordinate.");
1550 fpCommandPanTo -> SetGuidance
1551 ("Places the camera in this position right and up relative to standard"
1552 "\ntarget point (as seen from viewpoint direction).");
1553 parameter = new G4UIparameter("right", 'd', omitable = true);
1554 parameter -> SetCurrentAsDefault (true);
1555 fpCommandPanTo -> SetParameter (parameter);
1556 parameter = new G4UIparameter("up", 'd', omitable = true);
1557 parameter -> SetCurrentAsDefault (true);
1558 fpCommandPanTo -> SetParameter (parameter);
1559 parameter = new G4UIparameter ("unit", 's', omitable = true);
1560 parameter -> SetDefaultValue ("m");
1561 fpCommandPanTo -> SetParameter (parameter);
1562}
1563
1565 delete fpCommandPan;
1566 delete fpCommandPanTo;
1567}
1568
1570 G4String currentValue;
1571 if (command == fpCommandPan) {
1573 }
1574 else if (command == fpCommandPanTo) {
1575 currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
1576 }
1577 return currentValue;
1578}
1579
1581 G4String newValue) {
1582
1583
1585
1586 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1587 if (!currentViewer) {
1588 if (verbosity >= G4VisManager::errors) {
1589 G4cerr <<
1590 "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
1591 << G4endl;
1592 }
1593 return;
1594 }
1595
1596 G4ViewParameters vp = currentViewer->GetViewParameters();
1597
1598 if (command == fpCommandPan) {
1601 }
1602 else if (command == fpCommandPanTo) {
1605 }
1606
1607 if (verbosity >= G4VisManager::confirmations) {
1608 G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
1609 << G4endl;
1610 }
1611
1612 SetViewParameters(currentViewer, vp);
1613}
1614
1616
1618 G4bool omitable, currentAsDefault;
1619 fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
1620 fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
1621 fpCommand -> SetGuidance
1622 ("By default, acts on current viewer. \"/vis/viewer/list\""
1623 "\nto see possible viewers. Viewer becomes current.");
1624 fpCommand -> SetParameterName ("viewer-name",
1625 omitable = true,
1626 currentAsDefault = true);
1627}
1628
1630 delete fpCommand;
1631}
1632
1634 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1635 if (viewer) {
1636 return viewer -> GetName ();
1637 }
1638 else {
1639 return "none";
1640 }
1641}
1642
1644
1646
1647 G4String& rebuildName = newValue;
1648
1649 G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
1650 if (!viewer) {
1651 if (verbosity >= G4VisManager::errors) {
1652 G4cerr << "ERROR: Viewer \"" << rebuildName
1653 << "\" not found - \"/vis/viewer/list\" to see possibilities."
1654 << G4endl;
1655 }
1656 return;
1657 }
1658
1659 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1660 if (!sceneHandler) {
1661 if (verbosity >= G4VisManager::errors) {
1662 G4cerr << "ERROR: Viewer \"" << viewer->GetName() << "\"" <<
1663 " has no scene handler - report serious bug."
1664 << G4endl;
1665 }
1666 return;
1667 }
1668
1669 sceneHandler->ClearTransientStore();
1670 viewer->NeedKernelVisit();
1671 viewer->SetView();
1672 viewer->ClearView();
1673 viewer->DrawView();
1674
1675 // Check auto-refresh and print confirmations.
1676 RefreshIfRequired(viewer);
1677}
1678
1680
1682 G4bool omitable, currentAsDefault;
1683 fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
1684 fpCommand -> SetGuidance
1685 ("Refreshes viewer.");
1686 fpCommand -> SetGuidance
1687 ("By default, acts on current viewer. \"/vis/viewer/list\""
1688 "\nto see possible viewers. Viewer becomes current.");
1689 fpCommand -> SetParameterName ("viewer-name",
1690 omitable = true,
1691 currentAsDefault = true);
1692}
1693
1695 delete fpCommand;
1696}
1697
1699 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1700 return viewer ? viewer -> GetName () : G4String("none");
1701}
1702
1704
1706 G4bool warn(verbosity >= G4VisManager::warnings);
1707
1708 G4String& refreshName = newValue;
1709 G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
1710 if (!viewer) {
1711 if (verbosity >= G4VisManager::errors) {
1712 G4cerr << "ERROR: Viewer \"" << refreshName << "\"" <<
1713 " not found - \"/vis/viewer/list\"\n to see possibilities."
1714 << G4endl;
1715 }
1716 return;
1717 }
1718
1719 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1720 if (!sceneHandler) {
1721 if (verbosity >= G4VisManager::errors) {
1722 G4cerr << "ERROR: Viewer \"" << refreshName << "\"" <<
1723 " has no scene handler - report serious bug."
1724 << G4endl;
1725 }
1726 return;
1727 }
1728
1729 G4Scene* scene = sceneHandler->GetScene();
1730 if (!scene) {
1731 if (verbosity >= G4VisManager::confirmations) {
1732 G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1733 << "\", to which viewer \"" << refreshName << "\"" <<
1734 "\n is attached, has no scene - \"/vis/scene/create\" and"
1735 " \"/vis/sceneHandler/attach\""
1736 "\n (or use compound command \"/vis/drawVolume\")."
1737 << G4endl;
1738 }
1739 return;
1740 }
1741 if (scene->GetRunDurationModelList().empty()) {
1742 G4bool successful = scene -> AddWorldIfEmpty (warn);
1743 if (!successful) {
1744 if (verbosity >= G4VisManager::warnings) {
1745 G4cout <<
1746 "WARNING: Scene is empty. Perhaps no geometry exists."
1747 "\n Try /run/initialize."
1748 << G4endl;
1749 }
1750 return;
1751 }
1752 // Scene has changed. CheckSceneAndNotifyHandlers issues
1753 // /vis/scene/notifyHandlers, which does a refresh anyway, so the
1754 // ordinary refresh becomes part of the else phrase...
1756 } else {
1757 if (verbosity >= G4VisManager::confirmations) {
1758 G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
1759 << G4endl;
1760 }
1761 viewer -> SetView ();
1762 viewer -> ClearView ();
1763 viewer -> DrawView ();
1764 if (verbosity >= G4VisManager::confirmations) {
1765 G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
1766 "\n (You might also need \"/vis/viewer/update\".)" << G4endl;
1767 }
1768 }
1769}
1770
1772
1774 G4bool omitable, currentAsDefault;
1775 fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
1776 fpCommand -> SetGuidance ("Resets viewer.");
1777 fpCommand -> SetGuidance
1778 ("By default, acts on current viewer. \"/vis/viewer/list\""
1779 "\nto see possible viewers. Viewer becomes current.");
1780 fpCommand -> SetParameterName ("viewer-name",
1781 omitable = true,
1782 currentAsDefault = true);
1783}
1784
1786 delete fpCommand;
1787}
1788
1790 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1791 if (viewer) {
1792 return viewer -> GetName ();
1793 }
1794 else {
1795 return "none";
1796 }
1797}
1798
1800
1802
1803 G4String& resetName = newValue;
1804 G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
1805 if (!viewer) {
1806 if (verbosity >= G4VisManager::errors) {
1807 G4cerr << "ERROR: Viewer \"" << resetName
1808 << "\" not found - \"/vis/viewer/list\" to see possibilities."
1809 << G4endl;
1810 }
1811 return;
1812 }
1813
1814 viewer->ResetView();
1815 RefreshIfRequired(viewer);
1816}
1817
1819
1821 G4bool omitable;
1822 fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this);
1823 fpCommand -> SetGuidance
1824 ("Write commands that define the current view to file.");
1825 fpCommand -> SetGuidance
1826 ("Read them back into the same or any viewer with \"/control/execute\".");
1827 fpCommand -> SetGuidance
1828 ("If the filename is omitted the view is saved to a file "
1829 "\"g4_nn.g4view\", where nn is a sequential two-digit number.");
1830 fpCommand -> SetGuidance
1831 ("If the filename is \"-\", the data are written to G4cout.");
1832 fpCommand -> SetGuidance
1833 ("If you are wanting to save views for future interpolation a recommended "
1834 "procedure is: save views to \"g4_nn.g4view\", as above, then move the files "
1835 "into a sub-directory, say, \"views\", then interpolate with"
1836 "\"/vis/viewer/interpolate views\"");
1837 fpCommand -> SetParameterName ("filename", omitable = true);
1838 fpCommand -> SetDefaultValue ("");
1839}
1840
1842 delete fpCommand;
1843}
1844
1846(G4UIcommand*) {
1847 return "";
1848}
1849
1850namespace {
1852 (std::ostream& os,
1853 const G4ViewParameters& vp,
1854 const G4Point3D& stp) // Standard Target Point
1855 {
1856 os
1857 << vp.CameraAndLightingCommands(stp)
1858 << vp.DrawingStyleCommands()
1860 << vp.TouchableCommands()
1861 << vp.TimeWindowCommands()
1862 << std::endl;
1863 }
1864}
1865
1867
1869
1870 const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1871 if (!currentViewer) {
1872 if (verbosity >= G4VisManager::errors) {
1873 G4cerr <<
1874 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer."
1875 << G4endl;
1876 }
1877 return;
1878 }
1879
1880 const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
1881 if (!currentScene) {
1882 if (verbosity >= G4VisManager::errors) {
1883 G4cerr <<
1884 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene."
1885 << G4endl;
1886 }
1887 return;
1888 }
1889
1890 // Get view parameters and ther relevant information.
1891 G4ViewParameters vp = currentViewer->GetViewParameters();
1892 // Concatenate any private vis attributes modifiers...
1893 const std::vector<G4ModelingParameters::VisAttributesModifier>*
1894 privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
1895 if (privateVAMs) {
1896 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i;
1897 for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) {
1899 }
1900 }
1901 const G4Point3D& stp = currentScene->GetStandardTargetPoint();
1902
1903 G4String filename = newValue;
1904
1905 if (newValue.length() == 0) {
1906 // Null filename - generate a filename
1907 const G4int maxNoOfFiles = 100;
1908 static G4int sequenceNumber = 0;
1909 if (sequenceNumber >= maxNoOfFiles) {
1910 if (verbosity >= G4VisManager::errors) {
1911 G4cerr
1912 << "ERROR: G4VisCommandsViewerSave::SetNewValue: Maximum number, "
1913 << maxNoOfFiles
1914 << ", of files exceeded."
1915 << G4endl;
1916 }
1917 return;
1918 }
1919 std::ostringstream oss;
1920 oss << std::setw(2) << std::setfill('0') << sequenceNumber++;
1921 filename = "g4_" + oss.str() + ".g4view";
1922 }
1923
1924 if (filename == "-") {
1925 // Write to standard output
1926 WriteCommands(G4cout,vp,stp);
1927 } else {
1928 // Write to file - but add extension if not prescribed
1929 if (!G4StrUtil::contains(filename, '.')) {
1930 // No extension supplied - add .g4view
1931 filename += ".g4view";
1932 }
1933 std::ofstream ofs(filename);
1934 if (!ofs) {
1935 if (verbosity >= G4VisManager::errors) {
1936 G4cerr <<
1937 "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
1938 << filename << "\"."
1939 << G4endl;
1940 }
1941 ofs.close();
1942 return;
1943 }
1944 WriteCommands(ofs,vp,stp);
1945 ofs.close();
1946 }
1947
1948 if (verbosity >= G4VisManager::warnings) {
1949 G4cout << "Viewer \"" << currentViewer -> GetName ()
1950 << "\"" << " saved to ";
1951 if (filename == "-") {
1952 G4cout << "G4cout.";
1953 } else {
1954 G4cout << "file \'" << filename << "\"." <<
1955 "\n Read the view back into this or any viewer with"
1956 "\n \"/control/execute " << filename << "\" or use"
1957 "\n \"/vis/viewer/interpolate\" if you have several saved files -"
1958 "\n see \"help /vis/viewer/interpolate\" for guidance.";
1959 }
1960 G4cout << G4endl;
1961 }
1962}
1963
1965
1967 fScaleMultiplier (G4Vector3D (1., 1., 1.)),
1968 fScaleTo (G4Vector3D (1., 1., 1.))
1969{
1970 G4bool omitable, currentAsDefault;
1971
1973 ("/vis/viewer/scale", this);
1974 fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
1975 fpCommandScale -> SetGuidance
1976 ("Multiplies components of current scaling by components of this factor."
1977 "\n Scales (x,y,z) by corresponding components of the resulting factor.");
1978 fpCommandScale -> SetGuidance
1979 ("");
1980 fpCommandScale -> SetParameterName
1981 ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
1982 omitable=true, currentAsDefault=true);
1983
1985 ("/vis/viewer/scaleTo", this);
1986 fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
1987 fpCommandScaleTo -> SetGuidance
1988 ("Scales (x,y,z) by corresponding components of this factor.");
1989 fpCommandScaleTo -> SetParameterName
1990 ("x-scale-factor","y-scale-factor","z-scale-factor",
1991 omitable=true, currentAsDefault=true);
1992}
1993
1995 delete fpCommandScale;
1996 delete fpCommandScaleTo;
1997}
1998
2000 G4String currentValue;
2001 if (command == fpCommandScale) {
2003 }
2004 else if (command == fpCommandScaleTo) {
2006 }
2007 return currentValue;
2008}
2009
2011 G4String newValue) {
2012
2013
2015
2016 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
2017 if (!currentViewer) {
2018 if (verbosity >= G4VisManager::errors) {
2019 G4cerr <<
2020 "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
2021 << G4endl;
2022 }
2023 return;
2024 }
2025
2026 G4ViewParameters vp = currentViewer->GetViewParameters();
2027
2028 if (command == fpCommandScale) {
2031 }
2032 else if (command == fpCommandScaleTo) {
2035 }
2036
2037 if (verbosity >= G4VisManager::confirmations) {
2038 G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
2039 }
2040
2041 SetViewParameters(currentViewer, vp);
2042}
2043
2045
2047 G4bool omitable;
2048 fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
2049 fpCommand -> SetGuidance ("Selects viewer.");
2050 fpCommand -> SetGuidance
2051 ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers.");
2052 fpCommand -> SetParameterName ("viewer-name", omitable = false);
2053}
2054
2056 delete fpCommand;
2057}
2058
2060 return "";
2061}
2062
2064
2066
2067 G4String& selectName = newValue;
2068 G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
2069
2070 if (!viewer) {
2071 if (verbosity >= G4VisManager::errors) {
2072 G4cerr << "ERROR: Viewer \"" << selectName << "\"";
2073 G4cerr << " not found - \"/vis/viewer/list\""
2074 "\n to see possibilities."
2075 << G4endl;
2076 }
2077 return;
2078 }
2079
2080 if (viewer == fpVisManager -> GetCurrentViewer ()) {
2081 if (verbosity >= G4VisManager::warnings) {
2082 G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
2083 << " already selected." << G4endl;
2084 }
2085 return;
2086 }
2087
2088 // Set pointers, call SetView and print confirmation.
2089 fpVisManager -> SetCurrentViewer (viewer);
2090
2091 RefreshIfRequired(viewer);
2092}
2093
2095
2097 G4bool omitable, currentAsDefault;
2098 fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
2099 fpCommand -> SetGuidance
2100 ("Triggers graphical database post-processing for viewers"
2101 "\nusing that technique.");
2102 fpCommand -> SetGuidance
2103 ("For such viewers the view only becomes visible with this command."
2104 "\nBy default, acts on current viewer. \"/vis/viewer/list\""
2105 "\nto see possible viewers. Viewer becomes current.");
2106 fpCommand -> SetParameterName ("viewer-name",
2107 omitable = true,
2108 currentAsDefault = true);
2109}
2110
2112 delete fpCommand;
2113}
2114
2116 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
2117 if (viewer) {
2118 return viewer -> GetName ();
2119 }
2120 else {
2121 return "none";
2122 }
2123}
2124
2126
2128
2129 G4String& updateName = newValue;
2130
2131 G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
2132 if (!viewer) {
2133 if (verbosity >= G4VisManager::errors) {
2134 G4cout <<
2135 "WARNING: command \"/vis/viewer/update\" could not be applied: no current viewer."
2136 << G4endl;
2137 }
2138 return;
2139 }
2140
2141 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
2142 if (!sceneHandler) {
2143 if (verbosity >= G4VisManager::errors) {
2144 G4cerr << "ERROR: Viewer \"" << updateName << "\"" <<
2145 " has no scene handler - report serious bug."
2146 << G4endl;
2147 }
2148 return;
2149 }
2150
2151 G4Scene* scene = sceneHandler->GetScene();
2152 if (!scene) {
2153 if (verbosity >= G4VisManager::confirmations) {
2154 G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
2155 << "\", to which viewer \"" << updateName << "\"" <<
2156 "\n is attached, has no scene - \"/vis/scene/create\" and"
2157 " \"/vis/sceneHandler/attach\""
2158 "\n (or use compound command \"/vis/drawVolume\")."
2159 << G4endl;
2160 }
2161 return;
2162 }
2163
2164 if (verbosity >= G4VisManager::confirmations) {
2165 G4cout << "Viewer \"" << viewer -> GetName () << "\"";
2166 G4cout << " post-processing triggered." << G4endl;
2167 }
2168 viewer -> ShowView ();
2169 // Assume future need to "refresh" transients...
2170 sceneHandler -> SetMarkForClearingTransientStore(true);
2171}
2172
2174
2176 fZoomMultiplier (1.),
2177 fZoomTo (1.)
2178{
2179 G4bool omitable, currentAsDefault;
2180
2182 ("/vis/viewer/zoom", this);
2183 fpCommandZoom -> SetGuidance ("Incremental zoom.");
2184 fpCommandZoom -> SetGuidance
2185 ("Multiplies current magnification by this factor.");
2186 fpCommandZoom -> SetParameterName("multiplier",
2187 omitable=true,
2188 currentAsDefault=true);
2189
2191 ("/vis/viewer/zoomTo", this);
2192 fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
2193 fpCommandZoomTo -> SetGuidance
2194 ("Magnifies standard magnification by this factor.");
2195 fpCommandZoomTo -> SetParameterName("factor",
2196 omitable=true,
2197 currentAsDefault=true);
2198}
2199
2201 delete fpCommandZoom;
2202 delete fpCommandZoomTo;
2203}
2204
2206 G4String currentValue;
2207 if (command == fpCommandZoom) {
2209 }
2210 else if (command == fpCommandZoomTo) {
2211 currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
2212 }
2213 return currentValue;
2214}
2215
2217 G4String newValue) {
2218
2219
2221
2222 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
2223 if (!currentViewer) {
2224 if (verbosity >= G4VisManager::errors) {
2225 G4cerr <<
2226 "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
2227 << G4endl;
2228 }
2229 return;
2230 }
2231
2232 G4ViewParameters vp = currentViewer->GetViewParameters();
2233
2234 if (command == fpCommandZoom) {
2237 }
2238 else if (command == fpCommandZoomTo) {
2241 }
2242
2243 if (verbosity >= G4VisManager::confirmations) {
2244 G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
2245 }
2246
2247 SetViewParameters(currentViewer, vp);
2248}
static const G4double d1
static const G4double d2
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
HepGeom::Normal3D< G4double > G4Normal3D
Definition: G4Normal3D.hh:34
HepGeom::Plane3D< G4double > G4Plane3D
Definition: G4Plane3D.hh:36
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:34
static constexpr double millisecond
Definition: G4SIunits.hh:139
#define G4BestUnit(a, b)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
std::vector< G4Plane3D > G4Planes
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void DescribeYourselfTo(G4VGraphicsScene &)
const std::vector< Findings > & GetFindings() const
G4bool AddRunDurationModel(G4VModel *, G4bool warn=false)
Definition: G4Scene.cc:158
const std::vector< Model > & GetRunDurationModelList() const
const G4VisExtent & GetExtent() const
const G4Point3D & GetStandardTargetPoint() const
const G4String & GetName() const
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
size_t GetNoWorlds() const
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:363
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:445
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:584
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:200
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:199
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
const G4String & GetNickname() const
void SetModelingParameters(const G4ModelingParameters *)
virtual void ClearTransientStore()
void SetMarkForClearingTransientStore(G4bool)
G4VGraphicsSystem * GetGraphicsSystem() const
G4Scene * GetScene() const
const G4String & GetName() const
const G4String & GetName() const
virtual void DrawView()=0
const G4ViewParameters & GetViewParameters() const
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
void NeedKernelVisit()
Definition: G4VViewer.cc:78
virtual void FinishView()
Definition: G4VViewer.cc:101
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:120
void RefreshView()
virtual void ClearView()=0
G4VSceneHandler * GetSceneHandler() const
virtual void SetView()=0
virtual void ResetView()
void CopyCameraParameters(G4ViewParameters &target, const G4ViewParameters &from)
void CheckSceneAndNotifyHandlers(G4Scene *=nullptr)
static G4VisManager * fpVisManager
void InterpolateToNewView(G4VViewer *currentViewer, const G4ViewParameters &oldVP, const G4ViewParameters &newVP, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
static G4bool ConvertToDoublePair(const G4String &paramString, G4double &xval, G4double &yval)
void RefreshIfRequired(G4VViewer *viewer)
void SetViewParameters(G4VViewer *viewer, const G4ViewParameters &viewParams)
void CopyParametersFrom(const G4UIcommand *fromCmd, G4UIcommand *toCmd)
static G4ViewParameters fVPExistingViewer
G4bool ProvideValueOfUnit(const G4String &where, const G4String &unit, const G4String &category, G4double &value)
void CopyMostViewParameters(G4ViewParameters &target, const G4ViewParameters &from)
static G4bool fThereWasAViewer
static G4String ConvertToString(G4double x, G4double y, const char *unitName)
void CopyGuidanceFrom(const G4UIcommand *fromCmd, G4UIcommand *toCmd, G4int startLine=0)
void InterpolateViews(G4VViewer *currentViewer, std::vector< G4ViewParameters > viewVector, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
void SetCBDParameters(const std::vector< G4double > &)
void SetScaleFactor(const G4Vector3D &scaleFactor)
const G4Vector3D & GetScaleFactor() const
void SetAutoRefresh(G4bool)
const G4String & GetXGeometryString() const
G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
void SetCurrentTargetPoint(const G4Point3D &currentTargetPoint)
void ClearCutawayPlanes()
const G4Point3D & GetCurrentTargetPoint() const
void SetCBDAlgorithmNumber(G4int)
void MultiplyScaleFactor(const G4Vector3D &scaleFactorMultiplier)
G4double GetZoomFactor() const
void SetDolly(G4double dolly)
G4String SceneModifyingCommands() const
void IncrementPan(G4double right, G4double up)
G4String TimeWindowCommands() const
G4String TouchableCommands() const
const std::vector< G4double > & GetCBDParameters() const
G4int GetCBDAlgorithmNumber() const
void ChangeCutawayPlane(size_t index, const G4Plane3D &cutawayPlane)
void SetZoomFactor(G4double zoomFactor)
void SetPan(G4double right, G4double up)
const G4Planes & GetCutawayPlanes() const
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
G4String DrawingStyleCommands() const
G4bool IsAutoRefresh() const
void IncrementDolly(G4double dollyIncrement)
void ClearVisAttributesModifiers()
void AddCutawayPlane(const G4Plane3D &cutawayPlane)
G4double GetDolly() const
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)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithAString * fpCommand
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)
G4UIcmdWithADoubleAndUnit * fpCommandDollyTo
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithADoubleAndUnit * fpCommandDolly
G4UIcmdWithAString * fpCommand
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)
G4UIcmdWithAString * fpCommand
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithAString * fpCommand
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithAString * fpCommand
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithAString * fpCommand
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWith3Vector * fpCommandScale
G4UIcmdWith3Vector * fpCommandScaleTo
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithAString * fpCommand
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithAString * fpCommand
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithADouble * fpCommandZoom
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithADouble * fpCommandZoomTo
void SetNewValue(G4UIcommand *command, G4String newValue)
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:75
const G4Point3D & GetExtentCentre() const
Definition: G4VisExtent.cc:65
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
void ResetTransientsDrawnFlags()
void SetVerboseLevel(G4int)
static Verbosity GetVerbosityValue(const G4String &)
const char * name(G4int ptype)
void strip(G4String &str, char c=' ')
Remove leading and trailing characters from string.
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.
void WriteCommands(std::ostream &os, const G4ViewParameters &vp, const G4Point3D &stp)