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