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