Geant4 10.7.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 "G4ios.hh"
48#include <chrono>
49#include <thread>
50#include <sstream>
51#include <fstream>
52#include <sstream>
53#include <iomanip>
54#include <cstdio>
55#ifdef WIN32
56#include <regex>
57#include <filesystem>
58#endif //WIN32
59
60////////////// /vis/viewer/addCutawayPlane ///////////////////////////////////////
61
63 G4bool omitable;
64 fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
65 fpCommand -> SetGuidance
66 ("Add cutaway plane to current viewer.");
67 G4UIparameter* parameter;
68 parameter = new G4UIparameter("x",'d',omitable = true);
69 parameter -> SetDefaultValue (0);
70 parameter -> SetGuidance ("Coordinate of point on the plane.");
71 fpCommand->SetParameter(parameter);
72 parameter = new G4UIparameter("y",'d',omitable = true);
73 parameter -> SetDefaultValue (0);
74 parameter -> SetGuidance ("Coordinate of point on the plane.");
75 fpCommand->SetParameter(parameter);
76 parameter = new G4UIparameter("z",'d',omitable = true);
77 parameter -> SetDefaultValue (0);
78 parameter -> SetGuidance ("Coordinate of point on the plane.");
79 fpCommand->SetParameter(parameter);
80 parameter = new G4UIparameter("unit",'s',omitable = true);
81 parameter -> SetDefaultValue ("m");
82 parameter -> SetGuidance ("Unit of point on the plane.");
83 fpCommand->SetParameter(parameter);
84 parameter = new G4UIparameter("nx",'d',omitable = true);
85 parameter -> SetDefaultValue (1);
86 parameter -> SetGuidance ("Component of plane normal.");
87 fpCommand->SetParameter(parameter);
88 parameter = new G4UIparameter("ny",'d',omitable = true);
89 parameter -> SetDefaultValue (0);
90 parameter -> SetGuidance ("Component of plane normal.");
91 fpCommand->SetParameter(parameter);
92 parameter = new G4UIparameter("nz",'d',omitable = true);
93 parameter -> SetDefaultValue (0);
94 parameter -> SetGuidance ("Component of plane normal.");
95 fpCommand->SetParameter(parameter);
96}
97
99 delete fpCommand;
100}
101
103 return "";
104}
105
107
109
110 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
111 if (!viewer) {
112 if (verbosity >= G4VisManager::errors) {
113 G4cerr <<
114 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
115 << G4endl;
116 }
117 return;
118 }
119
120 G4double x, y, z, nx, ny, nz;
121 G4String unit;
122 std::istringstream is (newValue);
123 is >> x >> y >> z >> unit >> nx >> ny >> nz;
125 x *= F; y *= F; z *= F;
126
127 G4ViewParameters vp = viewer->GetViewParameters();
128 vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), 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 (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 G4cerr <<
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 size_t nWorlds = transportationManager->GetNoWorlds();
213 std::vector<G4PhysicalVolumesSearchScene::Findings> findingsVector;
214 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
215 transportationManager->GetWorldsIterator();
216 for (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 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 G4cerr
230 << "WARNING: Volume \"" << pvName << "\" ";
231 if (copyNo > 0) {
232 G4cerr << "copy number " << copyNo;
233 }
234 G4cerr << " not found." << G4endl;
235 }
236 return;
237 }
238
239 // Use a temporary scene in order to find vis extent
240 G4Scene tempScene("Centre Scene");
241 for (const auto& findings: findingsVector) {
242 // To handle paramaterisations we have to set the copy number
243 findings.fpFoundPV->SetCopyNo(findings.fFoundPVCopyNo);
244 // Create a temporary physical volume model.
245 // They have to be created on the heap because they have
246 // to hang about long enough to be conflated.
248 (findings.fpFoundPV,
249 0, // Only interested in top volume
250 findings.fFoundObjectTransformation,
251 0, // No modelling parameters (these are set later by the scene handler).
252 true, // Use full extent
253 findings.fFoundBasePVPath);
254 // ...and add it to the scene.
255 G4bool successful = tempScene.AddRunDurationModel(tempPVModel,warn);
256 if (successful) {
257 if (verbosity >= G4VisManager::confirmations) {
258 G4cout << "\"" << findings.fpFoundPV->GetName()
259 << "\", copy no. " << findings.fFoundPVCopyNo
260 << ",\n found in searched volume \""
261 << findings.fpSearchPV->GetName()
262 << "\" at depth " << findings.fFoundDepth
263 << ",\n base path: \"" << findings.fFoundBasePVPath
264 << ",\n has been added to temporary scene \"" << tempScene.GetName() << "\"."
265 << G4endl;
266 }
267 }
268 }
269 // Delete temporary physical volume models
270 for (const auto& sceneModel: tempScene.GetRunDurationModelList()) {
271 delete sceneModel.fpModel;
272 }
273
274 // Relevant results
275 const G4VisExtent& newExtent = tempScene.GetExtent();
276 const G4ThreeVector& newTargetPoint = newExtent.GetExtentCentre();
277
278 G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
279 G4ViewParameters saveVP = currentViewer->GetViewParameters();
280 G4ViewParameters newVP = saveVP;
281 if (command == fpCommandCentreAndZoomInOn) {
282 // Calculate the new zoom factor
283 const G4double zoomFactor
284 = currentScene->GetExtent().GetExtentRadius()/newExtent.GetExtentRadius();
285 newVP.SetZoomFactor(zoomFactor);
286 }
287 // Change the target point
288 const G4Point3D& standardTargetPoint = currentScene->GetStandardTargetPoint();
289 newVP.SetCurrentTargetPoint(newTargetPoint - standardTargetPoint);
290 // Interpolate
291 InterpolateToNewView(currentViewer, saveVP, newVP);
292
293 if (verbosity >= G4VisManager::confirmations) {
294 G4cout
295 << "Viewer \"" << currentViewer->GetName()
296 << "\" centred ";
297 if (fpCommandCentreAndZoomInOn) {
298 G4cout << "and zoomed in";
299 }
300 G4cout << " on physical volume(s) \"" << pvName << '\"'
301 << G4endl;
302 }
303
304 SetViewParameters(currentViewer, newVP);
305}
306
307////////////// /vis/viewer/changeCutawayPlane ///////////////////////////////////////
308
310 G4bool omitable;
311 fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
312 fpCommand -> SetGuidance("Change cutaway plane.");
313 G4UIparameter* parameter;
314 parameter = new G4UIparameter("index",'i',omitable = false);
315 parameter -> SetGuidance ("Index of plane: 0, 1, 2.");
316 fpCommand->SetParameter(parameter);
317 parameter = new G4UIparameter("x",'d',omitable = true);
318 parameter -> SetDefaultValue (0);
319 parameter -> SetGuidance ("Coordinate of point on the plane.");
320 fpCommand->SetParameter(parameter);
321 parameter = new G4UIparameter("y",'d',omitable = true);
322 parameter -> SetDefaultValue (0);
323 parameter -> SetGuidance ("Coordinate of point on the plane.");
324 fpCommand->SetParameter(parameter);
325 parameter = new G4UIparameter("z",'d',omitable = true);
326 parameter -> SetDefaultValue (0);
327 parameter -> SetGuidance ("Coordinate of point on the plane.");
328 fpCommand->SetParameter(parameter);
329 parameter = new G4UIparameter("unit",'s',omitable = true);
330 parameter -> SetDefaultValue ("m");
331 parameter -> SetGuidance ("Unit of point on the plane.");
332 fpCommand->SetParameter(parameter);
333 parameter = new G4UIparameter("nx",'d',omitable = true);
334 parameter -> SetDefaultValue (1);
335 parameter -> SetGuidance ("Component of plane normal.");
336 fpCommand->SetParameter(parameter);
337 parameter = new G4UIparameter("ny",'d',omitable = true);
338 parameter -> SetDefaultValue (0);
339 parameter -> SetGuidance ("Component of plane normal.");
340 fpCommand->SetParameter(parameter);
341 parameter = new G4UIparameter("nz",'d',omitable = true);
342 parameter -> SetDefaultValue (0);
343 parameter -> SetGuidance ("Component of plane normal.");
344 fpCommand->SetParameter(parameter);
345}
346
348 delete fpCommand;
349}
350
352 return "";
353}
354
356
358
359 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
360 if (!viewer) {
361 if (verbosity >= G4VisManager::errors) {
362 G4cerr <<
363 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
364 << G4endl;
365 }
366 return;
367 }
368
369 size_t index;
370 G4double x, y, z, nx, ny, nz;
371 G4String unit;
372 std::istringstream is (newValue);
373 is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
375 x *= F; y *= F; z *= F;
376
377 G4ViewParameters vp = viewer->GetViewParameters();
378 vp.ChangeCutawayPlane(index,
379 G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
380 if (verbosity >= G4VisManager::confirmations) {
381 G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
382 const G4Planes& cutaways = vp.GetCutawayPlanes();
383 for (size_t i = 0; i < cutaways.size(); ++i)
384 G4cout << "\n " << i << ": " << cutaways[i];
385 G4cout << G4endl;
386 }
387
388 SetViewParameters(viewer, vp);
389}
390
391////////////// /vis/viewer/clear ///////////////////////////////////////
392
394 G4bool omitable, currentAsDefault;
395 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
396 fpCommand -> SetGuidance ("Clears viewer.");
397 fpCommand -> SetGuidance
398 ("By default, clears current viewer. Specified viewer becomes current."
399 "\n\"/vis/viewer/list\" to see possible viewer names.");
400 fpCommand -> SetParameterName ("viewer-name",
401 omitable = true,
402 currentAsDefault = true);
403}
404
406 delete fpCommand;
407}
408
410 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
411 return viewer ? viewer -> GetName () : G4String("none");
412}
413
415
417
418 G4String& clearName = newValue;
419 G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
420 if (!viewer) {
421 if (verbosity >= G4VisManager::errors) {
422 G4cerr << "ERROR: Viewer \"" << clearName
423 << "\" not found - \"/vis/viewer/list\" to see possibilities."
424 << G4endl;
425 }
426 return;
427 }
428
429 viewer->SetView();
430 viewer->ClearView();
431 viewer->FinishView();
432 if (verbosity >= G4VisManager::confirmations) {
433 G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
434 }
435
436}
437
438////////////// /vis/viewer/clearCutawayPlanes ///////////////////////////////////////
439
441 fpCommand = new G4UIcmdWithoutParameter
442 ("/vis/viewer/clearCutawayPlanes", this);
443 fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
444}
445
447 delete fpCommand;
448}
449
451 return "";
452}
453
455
457
458 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
459 if (!viewer) {
460 if (verbosity >= G4VisManager::errors) {
461 G4cerr <<
462 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
463 << G4endl;
464 }
465 return;
466 }
467
468 G4ViewParameters vp = viewer->GetViewParameters();
470 if (verbosity >= G4VisManager::confirmations) {
471 G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
472 << "\" now cleared." << G4endl;
473 }
474
475 SetViewParameters(viewer, vp);
476}
477
478////////////// /vis/viewer/clearTransients //////////////////////////
479
481 G4bool omitable, currentAsDefault;
482 fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
483 fpCommand -> SetGuidance ("Clears transients from viewer.");
484 fpCommand -> SetGuidance
485 ("By default, operates on current viewer. Specified viewer becomes current."
486 "\n\"/vis/viewer/list\" to see possible viewer names.");
487 fpCommand -> SetParameterName ("viewer-name",
488 omitable = true,
489 currentAsDefault = true);
490}
491
493 delete fpCommand;
494}
495
497 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
498 return viewer ? viewer -> GetName () : G4String("none");
499}
500
502
504
505 G4String& clearName = newValue;
506 G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
507 if (!viewer) {
508 if (verbosity >= G4VisManager::errors) {
509 G4cerr << "ERROR: Viewer \"" << clearName
510 << "\" not found - \"/vis/viewer/list\" to see possibilities."
511 << G4endl;
512 }
513 return;
514 }
515
516 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
517 sceneHandler->SetMarkForClearingTransientStore(false);
519 sceneHandler->ClearTransientStore();
520 if (verbosity >= G4VisManager::confirmations) {
521 G4cout << "Viewer \"" << clearName << "\" cleared of transients."
522 << G4endl;
523 }
524
525}
526
527////////////// /vis/viewer/clearVisAttributesModifiers ///////////////////////////////////////
528
530 fpCommand = new G4UIcmdWithoutParameter
531 ("/vis/viewer/clearVisAttributesModifiers", this);
532 fpCommand -> SetGuidance ("Clear vis attribute modifiers of current viewer.");
533 fpCommand -> SetGuidance ("(These are used for touchables, etc.)");
534}
535
537 delete fpCommand;
538}
539
541 return "";
542}
543
545
547
548 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
549 if (!viewer) {
550 if (verbosity >= G4VisManager::errors) {
551 G4cerr <<
552 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
553 << G4endl;
554 }
555 return;
556 }
557
558 G4ViewParameters vp = viewer->GetViewParameters();
560 if (verbosity >= G4VisManager::confirmations) {
561 G4cout << "Vis attributes modifiers for viewer \"" << viewer->GetName()
562 << "\" now cleared." << G4endl;
563 }
564
565 SetViewParameters(viewer, vp);
566}
567
568////////////// /vis/viewer/clone ///////////////////////////////////////
569
571 G4bool omitable;
572 fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
573 fpCommand -> SetGuidance ("Clones viewer.");
574 fpCommand -> SetGuidance
575 ("By default, clones current viewer. Clone becomes current."
576 "\nClone name, if not provided, is derived from the original name."
577 "\n\"/vis/viewer/list\" to see possible viewer names.");
578 G4UIparameter* parameter;
579 parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
580 parameter -> SetCurrentAsDefault (true);
581 fpCommand -> SetParameter (parameter);
582 parameter = new G4UIparameter ("clone-name", 's', omitable = true);
583 parameter -> SetDefaultValue ("none");
584 fpCommand -> SetParameter (parameter);
585}
586
588 delete fpCommand;
589}
590
592 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
593 G4String originalName = viewer ? viewer -> GetName () : G4String("none");
594 return "\"" + originalName + "\"";
595}
596
598
600
601 G4String originalName, cloneName;
602 std::istringstream is (newValue);
603
604 // Need to handle the possibility that the names contain embedded
605 // blanks within quotation marks...
606 char c = ' ';
607 while (is.get(c) && c == ' '){}
608 if (c == '"') {
609 while (is.get(c) && c != '"') {originalName += c;}
610 }
611 else {
612 originalName += c;
613 while (is.get(c) && c != ' ') {originalName += c;}
614 }
615 originalName = originalName.strip (G4String::both, ' ');
616 originalName = originalName.strip (G4String::both, '"');
617
618 G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
619 if (!originalViewer) {
620 if (verbosity >= G4VisManager::errors) {
621 G4cerr << "ERROR: Viewer \"" << originalName
622 << "\" not found - \"/vis/viewer/list\" to see possibilities."
623 << G4endl;
624 }
625 return;
626 }
627 originalName = originalViewer->GetName(); // Ensures long name.
628
629 while (is.get(c) && c == ' '){}
630 if (c == '"') {
631 while (is.get(c) && c != '"') {cloneName += c;}
632 }
633 else {
634 cloneName += c;
635 while (is.get(c) && c != ' ') {cloneName += c;}
636 }
637 cloneName = cloneName.strip (G4String::both, ' ');
638 cloneName = cloneName.strip (G4String::both, '"');
639
640 G4bool errorWhileNaming = false;
641 if (cloneName == "none") {
642 G4int subID = 0;
643 do {
644 cloneName = originalName;
645 std::ostringstream oss;
646 oss << '-' << subID++;
647 G4String::size_type lastDashPosition, nextSpacePosition;
648 if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos &&
649 (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
650 G4String::npos) {
651 cloneName.insert(nextSpacePosition, oss.str());
652 } else {
653 G4String::size_type spacePosition = cloneName.find(' ');
654 if (spacePosition != G4String::npos)
655 cloneName.insert(spacePosition, oss.str());
656 else
657 errorWhileNaming = true;
658 }
659 } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName));
660 }
661
662 if (errorWhileNaming) {
663 if (verbosity >= G4VisManager::errors) {
664 G4cerr << "ERROR: While naming clone viewer \"" << cloneName
665 << "\"."
666 << G4endl;
667 }
668 return;
669 }
670
671 if (fpVisManager -> GetViewer (cloneName)) {
672 if (verbosity >= G4VisManager::errors) {
673 G4cerr << "ERROR: Putative clone viewer \"" << cloneName
674 << "\" already exists."
675 << G4endl;
676 }
677 return;
678 }
679
680 G4String windowSizeHint =
681 originalViewer->GetViewParameters().GetXGeometryString();
682
684 G4int keepVerbose = UImanager->GetVerboseLevel();
685 G4int newVerbose(0);
686 if (keepVerbose >= 2 ||
688 newVerbose = 2;
689 UImanager->SetVerboseLevel(newVerbose);
690 UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
691 UImanager->ApplyCommand
692 (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
693 UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
694 UImanager->SetVerboseLevel(keepVerbose);
695
696 if (verbosity >= G4VisManager::confirmations) {
697 G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
698 G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
699 }
700}
701
702////////////// /vis/viewer/colourByDensity ///////////////////////////////////////
703
705 G4bool omitable;
706 fpCommand = new G4UIcommand ("/vis/viewer/colourByDensity", this);
707 fpCommand -> SetGuidance
708 ("If a volume has no vis attributes, colour it by density.");
709 fpCommand -> SetGuidance
710 ("Provide algorithm number, e.g., \"1\" (or \"0\" to switch off)."
711 "\nThen a unit of density, e.g., \"g/cm3\"."
712 "\nThen parameters for the algorithm assumed to be densities in that unit.");
713 fpCommand -> SetGuidance
714 ("Algorithm 1: Simple algorithm takes 3 parameters: d0, d1 and d2."
715 "\n Volumes with density < d0 are invisible."
716 "\n Volumes with d0 <= density < d1 have colour on range red->green."
717 "\n Volumes with d1 <= density < d2 have colour on range green->blue."
718 "\n Volumes with density > d2 are blue.");
719 G4UIparameter* parameter;
720 parameter = new G4UIparameter("n",'i',omitable = true);
721 parameter -> SetGuidance ("Algorithm number (or \"0\" to switch off).");
722 parameter -> SetDefaultValue (1);
723 fpCommand->SetParameter(parameter);
724 parameter = new G4UIparameter("unit",'s',omitable = true);
725 parameter -> SetGuidance ("Unit of following densities, e.g., \"g/cm3\".");
726 parameter -> SetDefaultValue ("g/cm3");
727 fpCommand->SetParameter(parameter);
728 parameter = new G4UIparameter("d0",'d',omitable = true);
729 parameter -> SetGuidance ("Density parameter 0");
730 parameter -> SetDefaultValue (0.5);
731 fpCommand->SetParameter(parameter);
732 parameter = new G4UIparameter("d1",'d',omitable = true);
733 parameter -> SetGuidance ("Density parameter 1");
734 parameter -> SetDefaultValue (3.0);
735 fpCommand->SetParameter(parameter);
736 parameter = new G4UIparameter("d2",'d',omitable = true);
737 parameter -> SetGuidance ("Density parameter 2.");
738 parameter -> SetDefaultValue (10.0);
739 fpCommand->SetParameter(parameter);
740}
741
743 delete fpCommand;
744}
745
747 return "";
748}
749
751
753
754 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
755 if (!viewer) {
756 if (verbosity >= G4VisManager::errors) {
757 G4cerr <<
758 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
759 << G4endl;
760 }
761 return;
762 }
763 G4ViewParameters vp = viewer->GetViewParameters();
764
765 G4int algorithmNumber;
766 G4double d0, d1, d2;
767 G4String unit;
768 std::istringstream is (newValue);
769 is >> algorithmNumber >> unit >> d0 >> d1 >> d2;
770
771 if (algorithmNumber < 0 || algorithmNumber > 1) {
772 if (verbosity >= G4VisManager::errors) {
773 G4cerr <<
774 "ERROR: Unrecognised algorithm number: " << algorithmNumber
775 << G4endl;
776 }
777 return;
778 }
779
780 std::vector<G4double> parameters;
781 if (algorithmNumber > 0) {
782 const G4String where = "G4VisCommandViewerColourByDensity::SetNewValue";
783 G4double valueOfUnit;
784 // "Volumic Mass" is Michel's phrase for "Density"
785 if (ProvideValueOfUnit(where,unit,"Volumic Mass",valueOfUnit)) {
786 // Successful outcome of unit search
787 d0 *= valueOfUnit; d1 *= valueOfUnit; d2 *= valueOfUnit;
788 } else {
789 if (verbosity >= G4VisManager::errors) {
790 G4cerr <<
791 "ERROR: Unrecognised or inappropriate unit: " << unit
792 << G4endl;
793 }
794 return;
795 }
796 parameters.push_back(d0);
797 parameters.push_back(d1);
798 parameters.push_back(d2);
799 }
800 vp.SetCBDAlgorithmNumber(algorithmNumber);
801 vp.SetCBDParameters(parameters);
802
803 if (verbosity >= G4VisManager::confirmations) {
804 if (vp.GetCBDAlgorithmNumber() == 0) {
805 G4cout << "Colour by density deactivated" << G4endl;
806 } else {
807 G4cout << "Colour by density algorithm " << vp.GetCBDAlgorithmNumber()
808 << " selected for viewer \"" << viewer->GetName()
809 << "\n Parameters:";
810 for (auto p: vp.GetCBDParameters()) {
811 G4cout << ' ' << G4BestUnit(p,"Volumic Mass");
812 }
813 G4cout << G4endl;
814 }
815 }
816
817 SetViewParameters(viewer, vp);
818}
819
820////////////// /vis/viewer/copyViewFrom //////////////////////////
821
823 G4bool omitable;
824 fpCommand = new G4UIcmdWithAString ("/vis/viewer/copyViewFrom", this);
825 fpCommand -> SetGuidance
826 ("Copy the camera-specific parameters from the specified viewer.");
827 fpCommand -> SetGuidance
828 ("Note: To copy ALL view parameters, including scene modifications,"
829 "\nuse \"/vis/viewer/set/all\"");
830 fpCommand -> SetParameterName ("from-viewer-name", omitable = false);
831}
832
834 delete fpCommand;
835}
836
838 return "";
839}
840
842
844
845 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
846 if (!currentViewer) {
847 if (verbosity >= G4VisManager::errors) {
848 G4cerr <<
849 "ERROR: G4VisCommandsViewerCopyViewFrom::SetNewValue: no current viewer."
850 << G4endl;
851 }
852 return;
853 }
854
855 const G4String& fromViewerName = newValue;
856 G4VViewer* fromViewer = fpVisManager -> GetViewer (fromViewerName);
857 if (!fromViewer) {
858 if (verbosity >= G4VisManager::errors) {
859 G4cerr << "ERROR: Viewer \"" << fromViewerName
860 << "\" not found - \"/vis/viewer/list\" to see possibilities."
861 << G4endl;
862 }
863 return;
864 }
865
866 if (fromViewer == currentViewer) {
867 if (verbosity >= G4VisManager::warnings) {
868 G4cout <<
869 "WARNING: G4VisCommandsViewerSet::SetNewValue:"
870 "\n from-viewer and current viewer are identical."
871 << G4endl;
872 }
873 return;
874 }
875
876 // Copy camera-specific view parameters
877 G4ViewParameters vp = currentViewer->GetViewParameters();
878 const G4ViewParameters& fromVP = fromViewer->GetViewParameters();
882 vp.SetUpVector (fromVP.GetUpVector());
884 vp.SetZoomFactor (fromVP.GetZoomFactor());
885 vp.SetScaleFactor (fromVP.GetScaleFactor());
887 vp.SetDolly (fromVP.GetDolly());
888 SetViewParameters(currentViewer, vp);
889
890 if (verbosity >= G4VisManager::confirmations) {
891 G4cout << "Camera parameters of viewer \"" << currentViewer->GetName()
892 << "\"\n set to those of viewer \"" << fromViewer->GetName()
893 << "\"."
894 << G4endl;
895 }
896}
897
898////////////// /vis/viewer/create ///////////////////////////////////////
899
901 G4bool omitable;
902 fpCommand = new G4UIcommand ("/vis/viewer/create", this);
903 fpCommand -> SetGuidance
904 ("Creates a viewer for the specified scene handler.");
905 fpCommand -> SetGuidance
906 ("Default scene handler is the current scene handler. Invents a name"
907 "\nif not supplied. (Note: the system adds information to the name"
908 "\nfor identification - only the characters up to the first blank are"
909 "\nused for removing, selecting, etc.) This scene handler and viewer"
910 "\nbecome current.");
911 G4UIparameter* parameter;
912 parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
913 parameter -> SetCurrentAsDefault (true);
914 fpCommand -> SetParameter (parameter);
915 parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
916 parameter -> SetCurrentAsDefault (true);
917 fpCommand -> SetParameter (parameter);
918 parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
919 parameter->SetGuidance
920 ("integer (pixels) for square window placed by window manager or"
921 " X-Windows-type geometry string, e.g. 600x600-100+100");
922 parameter->SetDefaultValue("600");
923 fpCommand -> SetParameter (parameter);
924}
925
927 delete fpCommand;
928}
929
930G4String G4VisCommandViewerCreate::NextName () {
931 std::ostringstream oss;
932 G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
933 oss << "viewer-" << fId << " (";
934 if (sceneHandler) {
935 oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
936 }
937 else {
938 oss << "no_scene_handlers";
939 }
940 oss << ")";
941 return oss.str();
942}
943
945 G4String currentValue;
946 G4VSceneHandler* currentSceneHandler =
947 fpVisManager -> GetCurrentSceneHandler ();
948 if (currentSceneHandler) {
949 currentValue = currentSceneHandler -> GetName ();
950 }
951 else {
952 currentValue = "none";
953 }
954 currentValue += ' ';
955 currentValue += '"';
956 currentValue += NextName ();
957 currentValue += '"';
958
959 currentValue += " 600"; // Default number of pixels for window size hint.
960
961 return currentValue;
962}
963
965
967
968 G4String sceneHandlerName, newName;
969 G4String windowSizeHintString;
970 std::istringstream is (newValue);
971 is >> sceneHandlerName;
972
973 // Now need to handle the possibility that the second string
974 // contains embedded blanks within quotation marks...
975 char c = ' ';
976 while (is.get(c) && c == ' '){}
977 if (c == '"') {
978 while (is.get(c) && c != '"') {newName += c;}
979 }
980 else {
981 newName += c;
982 while (is.get(c) && c != ' ') {newName += c;}
983 }
984 newName = newName.strip (G4String::both, ' ');
985 newName = newName.strip (G4String::both, '"');
986
987 // Now get window size hint...
988 is >> windowSizeHintString;
989
990 const G4SceneHandlerList& sceneHandlerList =
991 fpVisManager -> GetAvailableSceneHandlers ();
992 G4int nHandlers = sceneHandlerList.size ();
993 if (nHandlers <= 0) {
994 if (verbosity >= G4VisManager::errors) {
995 G4cerr <<
996 "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
997 "\n Create a scene handler with \"/vis/sceneHandler/create\""
998 << G4endl;
999 }
1000 return;
1001 }
1002
1003 G4int iHandler;
1004 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
1005 if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
1006 }
1007
1008 if (iHandler < 0 || iHandler >= nHandlers) {
1009 // Invalid command line argument or none.
1010 // This shouldn't happen!!!!!!
1011 if (verbosity >= G4VisManager::errors) {
1012 G4cout << "G4VisCommandViewerCreate::SetNewValue:"
1013 " invalid scene handler specified."
1014 << G4endl;
1015 }
1016 return;
1017 }
1018
1019 // Valid index. Set current scene handler and graphics system in
1020 // preparation for creating viewer.
1021 G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
1022 if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
1023 fpVisManager -> SetCurrentSceneHandler (sceneHandler);
1024 }
1025
1026 // Now deal with name of viewer.
1027 G4String nextName = NextName ();
1028 if (newName == "") {
1029 newName = nextName;
1030 }
1031 if (newName == nextName) fId++;
1032 G4String newShortName = fpVisManager -> ViewerShortName (newName);
1033
1034 for (G4int ih = 0; ih < nHandlers; ih++) {
1035 G4VSceneHandler* sh = sceneHandlerList [ih];
1036 const G4ViewerList& viewerList = sh -> GetViewerList ();
1037 for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1038 if (viewerList [iViewer] -> GetShortName () == newShortName ) {
1039 if (verbosity >= G4VisManager::errors) {
1040 G4cerr << "ERROR: Viewer \"" << newShortName << "\" already exists."
1041 << G4endl;
1042 }
1043 return;
1044 }
1045 }
1046 }
1047
1048 // WindowSizeHint and XGeometryString are picked up from the vis
1049 // manager in the G4VViewer constructor. In G4VisManager, after Viewer
1050 // creation, we will store theses parameters in G4ViewParameters.
1051
1052 fpVisManager -> CreateViewer (newName,windowSizeHintString);
1053
1054 G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
1055 if (newViewer && newViewer -> GetName () == newName) {
1056 if (verbosity >= G4VisManager::confirmations) {
1057 G4cout << "New viewer \"" << newName << "\" created." << G4endl;
1058 }
1059 }
1060 else {
1061 if (verbosity >= G4VisManager::errors) {
1062 if (newViewer) {
1063 G4cerr << "ERROR: New viewer doesn\'t match!!! Curious!!" << G4endl;
1064 } else {
1065 G4cout << "WARNING: No viewer created." << G4endl;
1066 }
1067 }
1068 }
1069 // Refresh if appropriate...
1070 if (newViewer) {
1071 if (newViewer->GetViewParameters().IsAutoRefresh()) {
1072 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
1073 }
1074 else {
1075 if (verbosity >= G4VisManager::warnings) {
1076 G4cout << "Issue /vis/viewer/refresh or flush to see effect."
1077 << G4endl;
1078 }
1079 }
1080 }
1081}
1082
1083////////////// /vis/viewer/dolly and dollyTo ////////////////////////////
1084
1086 fDollyIncrement (0.),
1087 fDollyTo (0.)
1088{
1089 G4bool omitable, currentAsDefault;
1090
1091 fpCommandDolly = new G4UIcmdWithADoubleAndUnit
1092 ("/vis/viewer/dolly", this);
1093 fpCommandDolly -> SetGuidance
1094 ("Incremental dolly.");
1095 fpCommandDolly -> SetGuidance
1096 ("Moves the camera incrementally towards target point.");
1097 fpCommandDolly -> SetParameterName("increment",
1098 omitable=true,
1099 currentAsDefault=true);
1100 fpCommandDolly -> SetDefaultUnit("m");
1101
1102 fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
1103 ("/vis/viewer/dollyTo", this);
1104 fpCommandDollyTo -> SetGuidance
1105 ("Dolly to specific coordinate.");
1106 fpCommandDollyTo -> SetGuidance
1107 ("Places the camera towards target point relative to standard camera point.");
1108 fpCommandDollyTo -> SetParameterName("distance",
1109 omitable=true,
1110 currentAsDefault=true);
1111 fpCommandDollyTo -> SetDefaultUnit("m");
1112}
1113
1115 delete fpCommandDolly;
1116 delete fpCommandDollyTo;
1117}
1118
1120 G4String currentValue;
1121 if (command == fpCommandDolly) {
1122 currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
1123 }
1124 else if (command == fpCommandDollyTo) {
1125 currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
1126 }
1127 return currentValue;
1128}
1129
1131 G4String newValue) {
1132
1133
1135
1136 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1137 if (!currentViewer) {
1138 if (verbosity >= G4VisManager::errors) {
1139 G4cerr <<
1140 "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
1141 << G4endl;
1142 }
1143 return;
1144 }
1145
1146 G4ViewParameters vp = currentViewer->GetViewParameters();
1147
1148 if (command == fpCommandDolly) {
1149 fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
1150 vp.IncrementDolly(fDollyIncrement);
1151 }
1152 else if (command == fpCommandDollyTo) {
1153 fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
1154 vp.SetDolly(fDollyTo);
1155 }
1156
1157 if (verbosity >= G4VisManager::confirmations) {
1158 G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
1159 }
1160
1161 SetViewParameters(currentViewer, vp);
1162}
1163
1164////////////// /vis/viewer/flush ///////////////////////////////////////
1165
1167 G4bool omitable, currentAsDefault;
1168 fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
1169 fpCommand -> SetGuidance
1170 ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
1171 fpCommand -> SetGuidance
1172 ("Useful for refreshing and initiating post-processing for graphics"
1173 "\nsystems which need post-processing. By default, acts on current"
1174 "\nviewer. \"/vis/viewer/list\" to see possible viewers. Viewer"
1175 "\nbecomes current.");
1176 fpCommand -> SetParameterName ("viewer-name",
1177 omitable = true,
1178 currentAsDefault = true);
1179}
1180
1182 delete fpCommand;
1183}
1184
1186(G4UIcommand*) {
1187 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1188 return viewer ? viewer -> GetName () : G4String("none");
1189}
1190
1192
1194
1195 G4String& flushName = newValue;
1196 G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
1197 if (!viewer) {
1198 if (verbosity >= G4VisManager::errors) {
1199 G4cerr << "ERROR: Viewer \"" << flushName << "\"" <<
1200 " not found - \"/vis/viewer/list\"\n to see possibilities."
1201 << G4endl;
1202 }
1203 return;
1204 }
1205
1207 G4int keepVerbose = ui->GetVerboseLevel();
1208 G4int newVerbose(0);
1209 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
1210 newVerbose = 2;
1211 ui->SetVerboseLevel(newVerbose);
1212 ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
1213 ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
1214 ui->SetVerboseLevel(keepVerbose);
1215 if (verbosity >= G4VisManager::confirmations) {
1216 G4cout << "Viewer \"" << viewer -> GetName () << "\""
1217 << " flushed." << G4endl;
1218 }
1219}
1220
1221////////////// /vis/viewer/interpolate ///////////////////////////////////////
1222
1224 G4bool omitable;
1225 fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
1226 fpCommand -> SetGuidance
1227 ("Interpolate views defined by the first argument, which can contain "
1228 "Unix-shell-style pattern matching characters such as '*', '?' and '[' "
1229 "- see \"man sh\" and look for \"Pattern Matching\". The contents "
1230 "of each file are assumed to be \"/vis/viewer\" commands "
1231 "that specify a particular view. The files are processed in alphanumeric "
1232 "order of filename. The files may be written by hand or produced by the "
1233 "\"/vis/viewer/save\" command.");
1234 fpCommand -> SetGuidance
1235 ("The default is to search the working directory for files with a .g4view "
1236 "extension. Another procedure is to assemble view files in a subdirectory, "
1237 "e.g., \"myviews\"; then they can be interpolated with\n"
1238 "\"/vis/viewer/interpolate myviews/*\".");
1239 fpCommand -> SetGuidance
1240 ("To export interpolated views to file for a future possible movie, "
1241 "write \"export\" as 5th parameter (OpenGL only).");
1242 G4UIparameter* parameter;
1243 parameter = new G4UIparameter("pattern", 's', omitable = true);
1244 parameter -> SetGuidance("Pattern that defines the view files.");
1245 parameter -> SetDefaultValue("*.g4view");
1246 fpCommand -> SetParameter(parameter);
1247 parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
1248 parameter -> SetGuidance ("Number of interpolation points per interval.");
1249 parameter -> SetDefaultValue(50);
1250 fpCommand -> SetParameter(parameter);
1251 parameter = new G4UIparameter("wait-time", 's', omitable = true);
1252 parameter -> SetGuidance("Wait time per interpolated point");
1253 parameter -> SetDefaultValue("20.");
1254 fpCommand -> SetParameter(parameter);
1255 parameter = new G4UIparameter("time-unit", 's', omitable = true);
1256 parameter -> SetDefaultValue("millisecond");
1257 fpCommand -> SetParameter (parameter);
1258 parameter = new G4UIparameter("export", 's', omitable = true);
1259 parameter -> SetDefaultValue("no");
1260 fpCommand -> SetParameter (parameter);
1261}
1262
1264 delete fpCommand;
1265}
1266
1268 return "";
1269}
1270
1272
1274
1275 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1276 if (!currentViewer) {
1277 if (verbosity >= G4VisManager::errors) {
1278 G4cerr <<
1279 "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
1280 << G4endl;
1281 }
1282 return;
1283 }
1284
1285 G4String pattern;
1286 G4int nInterpolationPoints;
1287 G4String waitTimePerPointString;
1288 G4String timeUnit;
1289 G4String exportString;
1290
1291 std::istringstream iss (newValue);
1292 iss
1293 >> pattern
1294 >> nInterpolationPoints
1295 >> waitTimePerPointString
1296 >> timeUnit
1297 >> exportString;
1298 G4String waitTimePerPointDimString(waitTimePerPointString + ' ' + timeUnit);
1299 const G4double waitTimePerPoint =
1300 G4UIcommand::ConvertToDimensionedDouble(waitTimePerPointDimString.c_str());
1301 G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
1302 if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
1303
1305
1306 // Save current view parameters
1307 G4ViewParameters saveVP = currentViewer->GetViewParameters();
1308
1309 // Save current verbosities
1311 G4int keepUIVerbosity = uiManager->GetVerboseLevel();
1312
1313 // Set verbosities for this operation
1315 uiManager->SetVerboseLevel(0);
1316
1317 // Switch off auto-refresh while we read in the view files (it will be
1318 // restored later). Note: the view files do not set auto-refresh.
1319 G4ViewParameters non_auto = saveVP;
1320 non_auto.SetAutoRefresh(false);
1321 currentViewer->SetViewParameters(non_auto);
1322
1323 // View vector of way points
1324 std::vector<G4ViewParameters> viewVector;
1325
1326 const G4int safety = 9999;
1327 G4int safetyCount = 0;
1328 G4String pathname;
1329
1330#ifndef WIN32
1331
1332 // Execute pattern and get resulting list of files
1333 G4String shellCommand = "echo " + pattern;
1334 FILE *filelist = popen(shellCommand.c_str(), "r");
1335 if (!filelist) {
1336 if (verbosity >= G4VisManager::errors) {
1337 G4cerr
1338 << "ERROR: G4VisCommandViewerInterpolate::SetNewValue:"
1339 << "\n Error obtaining pipe."
1340 << G4endl;
1341 }
1342 return;
1343 }
1344
1345 // Build view vector of way points
1346 const size_t BUFLENGTH = 999999;
1347 char buf[BUFLENGTH];
1348 char* result = std::fgets(buf, BUFLENGTH, filelist);
1349 if (result) {
1350 std::istringstream fileliststream(result);
1351 while (fileliststream >> pathname
1352 && safetyCount++ < safety) { // Loop checking, 16.02.2016, J.Allison
1353 uiManager->ApplyCommand("/control/execute " + pathname);
1354 G4ViewParameters vp = currentViewer->GetViewParameters();
1355 // Set original auto-refresh status.
1356 vp.SetAutoRefresh(saveVP.IsAutoRefresh());
1357 viewVector.push_back(vp);
1358 }
1359 }
1360 pclose(filelist);
1361
1362#else // WIN32 (popen is not available in Windows)
1363
1364 std::filesystem::path filePattern = pattern.c_str();
1365
1366 // Default pattern : *.g4view
1367 // Translated to a regexp : ^.*\\.g4view
1368 // Convert pattern into a regexp
1369 std::string regexp_pattern("^" + filePattern.filename().string());
1370 std::string result_pattern = "";
1371 // Replace '.' by "\\."
1372 size_t currentPos = 0;
1373 size_t nextPos = 0;
1374 std::string currentReplacement = "";
1375 size_t pos1 = regexp_pattern.find('.', nextPos);
1376 size_t pos2 = regexp_pattern.find('*', nextPos);
1377 size_t pos3 = regexp_pattern.find('?', nextPos);
1378 while ((pos1 != std::string::npos) || (pos2 != std::string::npos) || (pos3 != std::string::npos)) {
1379 nextPos = pos1;
1380 currentReplacement = "\\.";
1381 if (pos2 < nextPos) {
1382 nextPos = pos2;
1383 currentReplacement = ".*";
1384 }
1385 if (pos3 < nextPos) {
1386 nextPos = pos3;
1387 currentReplacement = "(.{1,1})";
1388 }
1389 result_pattern += regexp_pattern.substr(currentPos, nextPos - currentPos) + currentReplacement;
1390 nextPos++;
1391 currentPos = nextPos;
1392 pos1 = regexp_pattern.find('.', currentPos);
1393 pos2 = regexp_pattern.find('*', currentPos);
1394 pos3 = regexp_pattern.find('?', currentPos);
1395 }
1396 result_pattern += regexp_pattern.substr(currentPos);
1397
1398 // Build view vector of way points
1399 // Add "./" for empty paths
1400 G4String parentPath(filePattern.parent_path().string().length() ? filePattern.parent_path().string() : std::string("./"));
1401 std::filesystem::path parentPathPattern = parentPath.c_str();
1402 // Iterate through files in directory and apply regex match to filter appropriate files
1403 std::regex result_pattern_regex (result_pattern, std::regex_constants::basic | std::regex_constants::icase);
1404 for (auto iter = std::filesystem::directory_iterator(parentPathPattern);
1405 iter != std::filesystem::directory_iterator() && safetyCount++ < safety;
1406 ++iter)
1407 {
1408 const auto& file = iter->path();
1409
1410 G4String filename(file.filename().string());
1411 if (std::regex_match(filename, result_pattern_regex))
1412 {
1413 uiManager->ApplyCommand("/control/execute " + filename);
1414 G4ViewParameters vp = currentViewer->GetViewParameters();
1415 // Set original auto-refresh status.
1416 vp.SetAutoRefresh(saveVP.IsAutoRefresh());
1417 viewVector.push_back(vp);
1418 }
1419 }
1420
1421#endif // WIN32
1422
1423 if (safetyCount >= safety) {
1424 if (verbosity >= G4VisManager::errors) {
1425 G4cout <<
1426 "/vis/viewer/interpolate:"
1427 "\n the number of way points exceeds the maximum currently allowed: "
1428 << safety << G4endl;
1429 }
1430 return;
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
1474 return "";
1475}
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 G4int nHandlers = sceneHandlerList.size ();
1497 G4bool found = false;
1498 G4bool foundCurrent = false;
1499 for (int 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 G4int nViewers = viewerList.size ();
1511 if (nViewers == 0) {
1512 G4cout << "\n No viewers for this scene handler." << G4endl;
1513 }
1514 else {
1515 for (int 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
1621
1622 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1623 if (!currentViewer) {
1624 if (verbosity >= G4VisManager::errors) {
1625 G4cerr <<
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
1666 delete fpCommand;
1667}
1668
1670 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1671 if (viewer) {
1672 return viewer -> GetName ();
1673 }
1674 else {
1675 return "none";
1676 }
1677}
1678
1680
1682
1683 G4String& rebuildName = newValue;
1684
1685 G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
1686 if (!viewer) {
1687 if (verbosity >= G4VisManager::errors) {
1688 G4cerr << "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 G4cerr << "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
1731 delete fpCommand;
1732}
1733
1735 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1736 return viewer ? viewer -> GetName () : G4String("none");
1737}
1738
1740
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 G4cerr << "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 G4cerr << "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 G4cout <<
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
1822 delete fpCommand;
1823}
1824
1826 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1827 if (viewer) {
1828 return viewer -> GetName ();
1829 }
1830 else {
1831 return "none";
1832 }
1833}
1834
1836
1838
1839 G4String& resetName = newValue;
1840 G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
1841 if (!viewer) {
1842 if (verbosity >= G4VisManager::errors) {
1843 G4cerr << "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/save ///////////////////////////////////////
1855
1857 G4bool omitable;
1858 fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this);
1859 fpCommand -> SetGuidance
1860 ("Write commands that define the current view to file.");
1861 fpCommand -> SetGuidance
1862 ("Read them back into the same or any viewer with \"/control/execute\".");
1863 fpCommand -> SetGuidance
1864 ("If the filename is omitted the view is saved to a file "
1865 "\"g4_nn.g4view\", where nn is a sequential two-digit number.");
1866 fpCommand -> SetGuidance
1867 ("If the filename is \"-\", the data are written to G4cout.");
1868 fpCommand -> SetGuidance
1869 ("If you are wanting to save views for future interpolation a recommended "
1870 "procedure is: save views to \"g4_nn.g4view\", as above, then move the files "
1871 "into a sub-directory, say, \"views\", then interpolate with"
1872 "\"/vis/viewer/interpolate views/\" (note the trailing \'/\').");
1873 fpCommand -> SetParameterName ("filename", omitable = true);
1874 fpCommand -> SetDefaultValue ("");
1875}
1876
1878 delete fpCommand;
1879}
1880
1882(G4UIcommand*) {
1883 return "";
1884}
1885
1886namespace {
1887 void WriteCommands
1888 (std::ostream& os,
1889 const G4ViewParameters& vp,
1890 const G4Point3D& stp) // Standard Target Point
1891 {
1892 os
1893 << vp.CameraAndLightingCommands(stp)
1894 << vp.DrawingStyleCommands()
1896 << vp.TouchableCommands()
1897 << vp.TimeWindowCommands()
1898 << std::endl;
1899 }
1900}
1901
1903
1905
1906 const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1907 if (!currentViewer) {
1908 if (verbosity >= G4VisManager::errors) {
1909 G4cerr <<
1910 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer."
1911 << G4endl;
1912 }
1913 return;
1914 }
1915
1916 const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
1917 if (!currentScene) {
1918 if (verbosity >= G4VisManager::errors) {
1919 G4cerr <<
1920 "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene."
1921 << G4endl;
1922 }
1923 return;
1924 }
1925
1926 // Get view parameters and ther relevant information.
1927 G4ViewParameters vp = currentViewer->GetViewParameters();
1928 // Concatenate any private vis attributes modifiers...
1929 const std::vector<G4ModelingParameters::VisAttributesModifier>*
1930 privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
1931 if (privateVAMs) {
1932 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i;
1933 for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) {
1935 }
1936 }
1937 const G4Point3D& stp = currentScene->GetStandardTargetPoint();
1938
1939 G4String filename = newValue;
1940
1941 if (newValue.length() == 0) {
1942 // Null filename - generate a filename
1943 const G4int maxNoOfFiles = 100;
1944 static G4int sequenceNumber = 0;
1945 if (sequenceNumber >= maxNoOfFiles) {
1946 if (verbosity >= G4VisManager::errors) {
1947 G4cerr
1948 << "ERROR: G4VisCommandsViewerSave::SetNewValue: Maximum number, "
1949 << maxNoOfFiles
1950 << ", of files exceeded."
1951 << G4endl;
1952 }
1953 return;
1954 }
1955 std::ostringstream oss;
1956 oss << std::setw(2) << std::setfill('0') << sequenceNumber++;
1957 filename = "g4_" + oss.str() + ".g4view";
1958 }
1959
1960 if (filename == "-") {
1961 // Write to standard output
1962 WriteCommands(G4cout,vp,stp);
1963 } else {
1964 // Write to file - but add extension if not prescribed
1965 if (!filename.contains('.')) {
1966 // No extension supplied - add .g4view
1967 filename += ".g4view";
1968 }
1969 std::ofstream ofs(filename);
1970 if (!ofs) {
1971 if (verbosity >= G4VisManager::errors) {
1972 G4cerr <<
1973 "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
1974 << filename << "\"."
1975 << G4endl;
1976 }
1977 ofs.close();
1978 return;
1979 }
1980 WriteCommands(ofs,vp,stp);
1981 ofs.close();
1982 }
1983
1984 if (verbosity >= G4VisManager::warnings) {
1985 G4cout << "Viewer \"" << currentViewer -> GetName ()
1986 << "\"" << " saved to ";
1987 if (filename == "-") {
1988 G4cout << "G4cout.";
1989 } else {
1990 G4cout << "file \'" << filename << "\"." <<
1991 "\n Read the view back into this or any viewer with"
1992 "\n \"/control/execute " << filename << "\" or use"
1993 "\n \"/vis/viewer/interpolate\" if you have several saved files -"
1994 "\n see \"help /vis/viewer/interpolate\" for guidance.";
1995 }
1996 G4cout << G4endl;
1997 }
1998}
1999
2000////////////// /vis/viewer/scale and scaleTo ////////////////////////////
2001
2003 fScaleMultiplier (G4Vector3D (1., 1., 1.)),
2004 fScaleTo (G4Vector3D (1., 1., 1.))
2005{
2006 G4bool omitable, currentAsDefault;
2007
2008 fpCommandScale = new G4UIcmdWith3Vector
2009 ("/vis/viewer/scale", this);
2010 fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
2011 fpCommandScale -> SetGuidance
2012 ("Multiplies components of current scaling by components of this factor."
2013 "\n Scales (x,y,z) by corresponding components of the resulting factor.");
2014 fpCommandScale -> SetGuidance
2015 ("");
2016 fpCommandScale -> SetParameterName
2017 ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
2018 omitable=true, currentAsDefault=true);
2019
2020 fpCommandScaleTo = new G4UIcmdWith3Vector
2021 ("/vis/viewer/scaleTo", this);
2022 fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
2023 fpCommandScaleTo -> SetGuidance
2024 ("Scales (x,y,z) by corresponding components of this factor.");
2025 fpCommandScaleTo -> SetParameterName
2026 ("x-scale-factor","y-scale-factor","z-scale-factor",
2027 omitable=true, currentAsDefault=true);
2028}
2029
2031 delete fpCommandScale;
2032 delete fpCommandScaleTo;
2033}
2034
2036 G4String currentValue;
2037 if (command == fpCommandScale) {
2038 currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
2039 }
2040 else if (command == fpCommandScaleTo) {
2041 currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
2042 }
2043 return currentValue;
2044}
2045
2047 G4String newValue) {
2048
2049
2051
2052 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
2053 if (!currentViewer) {
2054 if (verbosity >= G4VisManager::errors) {
2055 G4cerr <<
2056 "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
2057 << G4endl;
2058 }
2059 return;
2060 }
2061
2062 G4ViewParameters vp = currentViewer->GetViewParameters();
2063
2064 if (command == fpCommandScale) {
2065 fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
2066 vp.MultiplyScaleFactor(fScaleMultiplier);
2067 }
2068 else if (command == fpCommandScaleTo) {
2069 fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
2070 vp.SetScaleFactor(fScaleTo);
2071 }
2072
2073 if (verbosity >= G4VisManager::confirmations) {
2074 G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
2075 }
2076
2077 SetViewParameters(currentViewer, vp);
2078}
2079
2080////////////// /vis/viewer/select ///////////////////////////////////////
2081
2083 G4bool omitable;
2084 fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
2085 fpCommand -> SetGuidance ("Selects viewer.");
2086 fpCommand -> SetGuidance
2087 ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers.");
2088 fpCommand -> SetParameterName ("viewer-name", omitable = false);
2089}
2090
2092 delete fpCommand;
2093}
2094
2096 return "";
2097}
2098
2100
2102
2103 G4String& selectName = newValue;
2104 G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
2105
2106 if (!viewer) {
2107 if (verbosity >= G4VisManager::errors) {
2108 G4cerr << "ERROR: Viewer \"" << selectName << "\"";
2109 G4cerr << " not found - \"/vis/viewer/list\""
2110 "\n to see possibilities."
2111 << G4endl;
2112 }
2113 return;
2114 }
2115
2116 if (viewer == fpVisManager -> GetCurrentViewer ()) {
2117 if (verbosity >= G4VisManager::warnings) {
2118 G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
2119 << " already selected." << G4endl;
2120 }
2121 return;
2122 }
2123
2124 // Set pointers, call SetView and print confirmation.
2125 fpVisManager -> SetCurrentViewer (viewer);
2126
2127 RefreshIfRequired(viewer);
2128}
2129
2130////////////// /vis/viewer/update ///////////////////////////////////////
2131
2133 G4bool omitable, currentAsDefault;
2134 fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
2135 fpCommand -> SetGuidance
2136 ("Triggers graphical database post-processing for viewers"
2137 "\nusing that technique.");
2138 fpCommand -> SetGuidance
2139 ("For such viewers the view only becomes visible with this command."
2140 "\nBy default, acts on current viewer. \"/vis/viewer/list\""
2141 "\nto see possible viewers. Viewer becomes current.");
2142 fpCommand -> SetParameterName ("viewer-name",
2143 omitable = true,
2144 currentAsDefault = true);
2145}
2146
2148 delete fpCommand;
2149}
2150
2152 G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
2153 if (viewer) {
2154 return viewer -> GetName ();
2155 }
2156 else {
2157 return "none";
2158 }
2159}
2160
2162
2164
2165 G4String& updateName = newValue;
2166
2167 G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
2168 if (!viewer) {
2169 if (verbosity >= G4VisManager::errors) {
2170 G4cout <<
2171 "WARNING: command \"/vis/viewer/update\" could not be applied: no current viewer."
2172 << G4endl;
2173 }
2174 return;
2175 }
2176
2177 G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
2178 if (!sceneHandler) {
2179 if (verbosity >= G4VisManager::errors) {
2180 G4cerr << "ERROR: Viewer \"" << updateName << "\"" <<
2181 " has no scene handler - report serious bug."
2182 << G4endl;
2183 }
2184 return;
2185 }
2186
2187 G4Scene* scene = sceneHandler->GetScene();
2188 if (!scene) {
2189 if (verbosity >= G4VisManager::confirmations) {
2190 G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
2191 << "\", to which viewer \"" << updateName << "\"" <<
2192 "\n is attached, has no scene - \"/vis/scene/create\" and"
2193 " \"/vis/sceneHandler/attach\""
2194 "\n (or use compound command \"/vis/drawVolume\")."
2195 << G4endl;
2196 }
2197 return;
2198 }
2199
2200 if (verbosity >= G4VisManager::confirmations) {
2201 G4cout << "Viewer \"" << viewer -> GetName () << "\"";
2202 G4cout << " post-processing triggered." << G4endl;
2203 }
2204 viewer -> ShowView ();
2205 // Assume future need to "refresh" transients...
2206 sceneHandler -> SetMarkForClearingTransientStore(true);
2207}
2208
2209////////////// /vis/viewer/zoom and zoomTo ////////////////////////////
2210
2212 fZoomMultiplier (1.),
2213 fZoomTo (1.)
2214{
2215 G4bool omitable, currentAsDefault;
2216
2217 fpCommandZoom = new G4UIcmdWithADouble
2218 ("/vis/viewer/zoom", this);
2219 fpCommandZoom -> SetGuidance ("Incremental zoom.");
2220 fpCommandZoom -> SetGuidance
2221 ("Multiplies current magnification by this factor.");
2222 fpCommandZoom -> SetParameterName("multiplier",
2223 omitable=true,
2224 currentAsDefault=true);
2225
2226 fpCommandZoomTo = new G4UIcmdWithADouble
2227 ("/vis/viewer/zoomTo", this);
2228 fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
2229 fpCommandZoomTo -> SetGuidance
2230 ("Magnifies standard magnification by this factor.");
2231 fpCommandZoomTo -> SetParameterName("factor",
2232 omitable=true,
2233 currentAsDefault=true);
2234}
2235
2237 delete fpCommandZoom;
2238 delete fpCommandZoomTo;
2239}
2240
2242 G4String currentValue;
2243 if (command == fpCommandZoom) {
2244 currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
2245 }
2246 else if (command == fpCommandZoomTo) {
2247 currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
2248 }
2249 return currentValue;
2250}
2251
2253 G4String newValue) {
2254
2255
2257
2258 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
2259 if (!currentViewer) {
2260 if (verbosity >= G4VisManager::errors) {
2261 G4cerr <<
2262 "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
2263 << G4endl;
2264 }
2265 return;
2266 }
2267
2268 G4ViewParameters vp = currentViewer->GetViewParameters();
2269
2270 if (command == fpCommandZoom) {
2271 fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
2272 vp.MultiplyZoomFactor(fZoomMultiplier);
2273 }
2274 else if (command == fpCommandZoomTo) {
2275 fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
2276 vp.SetZoomFactor(fZoomTo);
2277 }
2278
2279 if (verbosity >= G4VisManager::confirmations) {
2280 G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
2281 }
2282
2283 SetViewParameters(currentViewer, vp);
2284}
HepGeom::Normal3D< G4double > G4Normal3D
Definition: G4Normal3D.hh:34
HepGeom::Plane3D< G4double > G4Plane3D
Definition: G4Plane3D.hh:36
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:34
#define G4BestUnit(a, b)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
std::vector< G4Plane3D > G4Planes
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void DescribeYourselfTo(G4VGraphicsScene &)
const std::vector< Findings > & GetFindings() const
G4bool AddRunDurationModel(G4VModel *, G4bool warn=false)
Definition: G4Scene.cc:50
const std::vector< Model > & GetRunDurationModelList() const
const G4VisExtent & GetExtent() const
const G4Point3D & GetStandardTargetPoint() const
const G4String & GetName() const
G4bool contains(const std::string &) const
G4String strip(G4int strip_Type=trailing, char c=' ')
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
size_t GetNoWorlds() const
static G4ThreeVector GetNew3VectorValue(const char *paramString)
static G4double GetNewDoubleValue(const char *paramString)
static G4double GetNewDoubleValue(const char *paramString)
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:348
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:430
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:570
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:193
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:192
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
const G4String & GetNickname() const
void SetModelingParameters(const G4ModelingParameters *)
virtual void ClearTransientStore()
void SetMarkForClearingTransientStore(G4bool)
G4VGraphicsSystem * GetGraphicsSystem() const
G4Scene * GetScene() const
const G4String & GetName() const
const G4String & GetName() const
virtual void DrawView()=0
const G4ViewParameters & GetViewParameters() const
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
void NeedKernelVisit()
Definition: G4VViewer.cc:77
virtual void FinishView()
Definition: G4VViewer.cc:100
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:119
void RefreshView()
virtual void ClearView()=0
G4VSceneHandler * GetSceneHandler() const
virtual void SetView()=0
virtual void ResetView()
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 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 SetViewpointDirection(const G4Vector3D &viewpointDirection)
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 G4Vector3D & GetLightpointDirection() const
void SetFieldHalfAngle(G4double fieldHalfAngle)
const G4Vector3D & GetViewpointDirection() const
void ClearCutawayPlanes()
const G4Point3D & GetCurrentTargetPoint() const
void SetCBDAlgorithmNumber(G4int)
void MultiplyScaleFactor(const G4Vector3D &scaleFactorMultiplier)
G4double GetFieldHalfAngle() const
G4double GetZoomFactor() const
void SetDolly(G4double dolly)
G4String SceneModifyingCommands() const
void IncrementPan(G4double right, G4double up)
const G4Vector3D & GetUpVector() const
G4String 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 SetUpVector(const G4Vector3D &upVector)
void SetPan(G4double right, G4double up)
const G4Planes & GetCutawayPlanes() const
void SetLightpointDirection(const G4Vector3D &lightpointDirection)
void SetLightsMoveWithCamera(G4bool moves)
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
G4String DrawingStyleCommands() const
G4bool IsAutoRefresh() const
G4bool GetLightsMoveWithCamera() const
void IncrementDolly(G4double dollyIncrement)
void 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)
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 &)