Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/management/src/G4VisCommandsTouchable.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/management/src/G4VisCommandsTouchable.cc (Version 11.3.0) and /visualization/management/src/G4VisCommandsTouchable.cc (Version 10.6.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27                                                    27 
 28 // /vis/touchable commands - John Allison  14t     28 // /vis/touchable commands - John Allison  14th May 2014
 29                                                    29 
 30 #include "G4VisCommandsTouchable.hh"               30 #include "G4VisCommandsTouchable.hh"
 31                                                    31 
 32 #include "G4UImanager.hh"                          32 #include "G4UImanager.hh"
 33 #include "G4UIcmdWithAString.hh"                   33 #include "G4UIcmdWithAString.hh"
 34 #include "G4UIcmdWithoutParameter.hh"              34 #include "G4UIcmdWithoutParameter.hh"
 35 #include "G4UIcmdWithABool.hh"                     35 #include "G4UIcmdWithABool.hh"
 36 #include "G4TransportationManager.hh"              36 #include "G4TransportationManager.hh"
 37 #include "G4TouchableUtils.hh"                     37 #include "G4TouchableUtils.hh"
 38 #include "G4PhysicalVolumesSearchScene.hh"         38 #include "G4PhysicalVolumesSearchScene.hh"
 39 #include "G4AttDef.hh"                             39 #include "G4AttDef.hh"
 40 #include "G4AttValue.hh"                           40 #include "G4AttValue.hh"
 41 #include "G4AttCheck.hh"                           41 #include "G4AttCheck.hh"
 42 #include "G4AxesModel.hh"                      << 
 43                                                << 
 44 #define G4warn G4cout                          << 
 45                                                    42 
 46 G4VisCommandsTouchable::G4VisCommandsTouchable     43 G4VisCommandsTouchable::G4VisCommandsTouchable()
 47 {                                                  44 {
 48   G4bool omitable;                                 45   G4bool omitable;
 49                                                    46 
 50   fpCommandCentreAndZoomInOn = new G4UIcmdWith     47   fpCommandCentreAndZoomInOn = new G4UIcmdWithoutParameter("/vis/touchable/centreAndZoomInOn",this);
 51   fpCommandCentreAndZoomInOn->SetGuidance ("Ce     48   fpCommandCentreAndZoomInOn->SetGuidance ("Centre and zoom in on the current touchable.");
 52   fpCommandCentreAndZoomInOn->SetGuidance          49   fpCommandCentreAndZoomInOn->SetGuidance
 53   ("Use \"/vis/set/touchable\" to set current      50   ("Use \"/vis/set/touchable\" to set current touchable.");
 54   fpCommandCentreAndZoomInOn->SetGuidance          51   fpCommandCentreAndZoomInOn->SetGuidance
 55   ("You may also need \"/vis/touchable/findPat     52   ("You may also need \"/vis/touchable/findPath\".");
 56   fpCommandCentreAndZoomInOn->SetGuidance          53   fpCommandCentreAndZoomInOn->SetGuidance
 57   ("Use \"/vis/touchable/set\" to set attribut     54   ("Use \"/vis/touchable/set\" to set attributes.");
 58                                                    55 
 59   fpCommandCentreOn = new G4UIcmdWithoutParame     56   fpCommandCentreOn = new G4UIcmdWithoutParameter("/vis/touchable/centreOn",this);
 60   fpCommandCentreOn->SetGuidance ("Centre the      57   fpCommandCentreOn->SetGuidance ("Centre the view on the current touchable.");
 61   // Pick up additional guidance from /vis/vie     58   // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
 62   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,     59   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandCentreOn,1);
 63                                                    60 
 64   fpCommandDraw = new G4UIcmdWithABool("/vis/t <<  61   fpCommandDraw = new G4UIcmdWithoutParameter("/vis/touchable/draw",this);
 65   fpCommandDraw->SetGuidance("Draw touchable."     62   fpCommandDraw->SetGuidance("Draw touchable.");
 66   fpCommandDraw->SetGuidance                   << 
 67   ("If parameter == true, also draw extent as  << 
 68   // Pick up additional guidance from /vis/vie     63   // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
 69   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,     64   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandDraw,1);
 70   fpCommandDraw->SetParameterName("extent", om << 
 71   fpCommandDraw->SetDefaultValue(false);       << 
 72                                                    65 
 73   fpCommandDump = new G4UIcmdWithoutParameter(     66   fpCommandDump = new G4UIcmdWithoutParameter("/vis/touchable/dump",this);
 74   fpCommandDump->SetGuidance("Dump touchable a     67   fpCommandDump->SetGuidance("Dump touchable attributes.");
 75   // Pick up additional guidance from /vis/vie     68   // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
 76   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,     69   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandDump,1);
 77                                                    70 
 78   fpCommandExtentForField = new G4UIcmdWithABo     71   fpCommandExtentForField = new G4UIcmdWithABool("/vis/touchable/extentForField",this);
 79   fpCommandExtentForField->SetGuidance("Set ex     72   fpCommandExtentForField->SetGuidance("Set extent for field.");
 80   fpCommandExtentForField->SetGuidance("If par     73   fpCommandExtentForField->SetGuidance("If parameter == true, also draw.");
 81   // Pick up additional guidance from /vis/vie     74   // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
 82   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,     75   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandExtentForField,1);
 83   fpCommandExtentForField->SetParameterName("d     76   fpCommandExtentForField->SetParameterName("draw", omitable = true);
 84   fpCommandExtentForField->SetDefaultValue(fal     77   fpCommandExtentForField->SetDefaultValue(false);
 85                                                    78 
 86   fpCommandFindPath = new G4UIcommand("/vis/to     79   fpCommandFindPath = new G4UIcommand("/vis/touchable/findPath",this);
 87   fpCommandFindPath->SetGuidance                   80   fpCommandFindPath->SetGuidance
 88   ("Prints the path to touchable and its logic     81   ("Prints the path to touchable and its logical volume mother"
 89    "\ngiven a physical volume name and copy no     82    "\ngiven a physical volume name and copy no.");
 90   fpCommandFindPath -> SetGuidance                 83   fpCommandFindPath -> SetGuidance
 91   ("A search of all worlds is made and all phy     84   ("A search of all worlds is made and all physical volume names are"
 92    "\nmatched against the argument of this com     85    "\nmatched against the argument of this command.  If this is of the"
 93    "\nform \"/regexp/\", where regexp is a reg     86    "\nform \"/regexp/\", where regexp is a regular expression (see C++ regex),"
 94    "\nthe physical volume name is matched agai     87    "\nthe physical volume name is matched against regexp by the usual rules"
 95    "\nof regular expression matching. Otherwis     88    "\nof regular expression matching. Otherwise an exact match is required."
 96    "\nFor example, \"/Shap/\" matches \"Shape1     89    "\nFor example, \"/Shap/\" matches \"Shape1\" and \"Shape2\".");
 97   fpCommandFindPath -> SetGuidance                 90   fpCommandFindPath -> SetGuidance
 98   ("It may help to see a textual representatio     91   ("It may help to see a textual representation of the geometry hierarchy of"
 99    "\nthe worlds. Try \"/vis/drawTree [worlds]     92    "\nthe worlds. Try \"/vis/drawTree [worlds]\" or one of the driver/browser"
100    "\ncombinations that have the required func     93    "\ncombinations that have the required functionality, e.g., HepRep.");
101   G4UIparameter* parameter;                        94   G4UIparameter* parameter;
102   parameter = new G4UIparameter ("physical-vol     95   parameter = new G4UIparameter ("physical-volume-name", 's', omitable = true);
103   parameter -> SetDefaultValue ("world");          96   parameter -> SetDefaultValue ("world");
104   fpCommandFindPath -> SetParameter (parameter     97   fpCommandFindPath -> SetParameter (parameter);
105   parameter = new G4UIparameter ("copy-no", 'i     98   parameter = new G4UIparameter ("copy-no", 'i', omitable = true);
106   parameter -> SetGuidance ("If negative, matc     99   parameter -> SetGuidance ("If negative, matches any copy no.");
107   parameter -> SetDefaultValue (-1);              100   parameter -> SetDefaultValue (-1);
108   fpCommandFindPath -> SetParameter (parameter    101   fpCommandFindPath -> SetParameter (parameter);
109                                                   102 
110   fpCommandLocalAxes = new G4UIcmdWithoutParam << 
111   fpCommandLocalAxes->SetGuidance("Draw local  << 
112   // Pick up additional guidance from /vis/vie << 
113   CopyGuidanceFrom(fpCommandCentreAndZoomInOn, << 
114                                                << 
115   fpCommandShowExtent = new G4UIcmdWithABool("    103   fpCommandShowExtent = new G4UIcmdWithABool("/vis/touchable/showExtent",this);
116   fpCommandShowExtent->SetGuidance("Print exte    104   fpCommandShowExtent->SetGuidance("Print extent of touchable.");
117   fpCommandShowExtent->SetGuidance("If paramet    105   fpCommandShowExtent->SetGuidance("If parameter == true, also draw.");
118   // Pick up additional guidance from /vis/vie    106   // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
119   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,    107   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandShowExtent,1);
120   fpCommandShowExtent->SetParameterName("draw"    108   fpCommandShowExtent->SetParameterName("draw", omitable = true);
121   fpCommandShowExtent->SetDefaultValue(false);    109   fpCommandShowExtent->SetDefaultValue(false);
122                                                   110 
123   fpCommandTwinkle = new G4UIcmdWithoutParamet << 
124   fpCommandTwinkle->SetGuidance("Cause touchab << 
125   // Pick up additional guidance from /vis/vie << 
126   CopyGuidanceFrom(fpCommandCentreAndZoomInOn, << 
127                                                << 
128   fpCommandVolumeForField = new G4UIcmdWithABo    111   fpCommandVolumeForField = new G4UIcmdWithABool("/vis/touchable/volumeForField",this);
129   fpCommandVolumeForField->SetGuidance("Set vo    112   fpCommandVolumeForField->SetGuidance("Set volume for field.");
130   fpCommandVolumeForField->SetGuidance("If par    113   fpCommandVolumeForField->SetGuidance("If parameter == true, also draw.");
131   // Pick up additional guidance from /vis/vie    114   // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
132   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,    115   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandVolumeForField,1);
133   fpCommandVolumeForField->SetParameterName("d    116   fpCommandVolumeForField->SetParameterName("draw", omitable = true);
134   fpCommandVolumeForField->SetDefaultValue(fal    117   fpCommandVolumeForField->SetDefaultValue(false);
135 }                                                 118 }
136                                                   119 
137 G4VisCommandsTouchable::~G4VisCommandsTouchabl    120 G4VisCommandsTouchable::~G4VisCommandsTouchable() {
138   delete fpCommandVolumeForField;                 121   delete fpCommandVolumeForField;
139   delete fpCommandTwinkle;                     << 
140   delete fpCommandShowExtent;                     122   delete fpCommandShowExtent;
141   delete fpCommandLocalAxes;                   << 
142   delete fpCommandFindPath;                       123   delete fpCommandFindPath;
143   delete fpCommandExtentForField;                 124   delete fpCommandExtentForField;
144   delete fpCommandDump;                           125   delete fpCommandDump;
145   delete fpCommandDraw;                           126   delete fpCommandDraw;
146   delete fpCommandCentreAndZoomInOn;              127   delete fpCommandCentreAndZoomInOn;
147   delete fpCommandCentreOn;                       128   delete fpCommandCentreOn;
148 }                                                 129 }
149                                                   130 
150 G4String G4VisCommandsTouchable::GetCurrentVal    131 G4String G4VisCommandsTouchable::GetCurrentValue(G4UIcommand*) {
151   return "";                                      132   return "";
152 }                                                 133 }
153                                                   134 
154 void G4VisCommandsTouchable::SetNewValue          135 void G4VisCommandsTouchable::SetNewValue
155 (G4UIcommand* command, G4String newValue)         136 (G4UIcommand* command, G4String newValue)
156 {                                                 137 {
157   G4VisManager::Verbosity verbosity = fpVisMan    138   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
158   G4bool warn = verbosity >= G4VisManager::war    139   G4bool warn = verbosity >= G4VisManager::warnings;
159                                                   140 
160   G4UImanager* UImanager = G4UImanager::GetUIp    141   G4UImanager* UImanager = G4UImanager::GetUIpointer();
161                                                   142 
162   G4TransportationManager* transportationManag    143   G4TransportationManager* transportationManager =
163   G4TransportationManager::GetTransportationMa    144   G4TransportationManager::GetTransportationManager ();
164                                                   145 
165   size_t nWorlds = transportationManager->GetN    146   size_t nWorlds = transportationManager->GetNoWorlds();
166                                                   147 
167   G4VPhysicalVolume* world = *(transportationM    148   G4VPhysicalVolume* world = *(transportationManager->GetWorldsIterator());
168   if (!world) {                                   149   if (!world) {
169     if (verbosity >= G4VisManager::errors) {      150     if (verbosity >= G4VisManager::errors) {
170       G4warn <<                                << 151       G4cerr <<
171       "ERROR: G4VisCommandsTouchable::SetNewVa    152       "ERROR: G4VisCommandsTouchable::SetNewValue:"
172       "\n  No world.  Maybe the geometry has n    153       "\n  No world.  Maybe the geometry has not yet been defined."
173       "\n  Try \"/run/initialize\""               154       "\n  Try \"/run/initialize\""
174       << G4endl;                                  155       << G4endl;
175     }                                             156     }
176     return;                                       157     return;
177   }                                               158   }
178                                                   159 
179   if (command == fpCommandDump) {              << 
180                                                << 
181     G4PhysicalVolumeModel::TouchableProperties << 
182     G4TouchableUtils::FindTouchableProperties( << 
183     if (properties.fpTouchablePV) {            << 
184       // To handle parameterisations we have t << 
185       properties.fpTouchablePV->SetCopyNo(prop << 
186       G4PhysicalVolumeModel tempPVModel        << 
187       (properties.fpTouchablePV,               << 
188        G4PhysicalVolumeModel::UNLIMITED,       << 
189        properties.fTouchableGlobalTransform,   << 
190        nullptr, // Modelling parameters (not u << 
191        true, // use full extent (prevents calc << 
192        properties.fTouchableBaseFullPVPath);   << 
193       const std::map<G4String,G4AttDef>* attDe << 
194       std::vector<G4AttValue>* attValues = tem << 
195       G4cout << G4AttCheck(attValues,attDefs); << 
196       delete attValues;                        << 
197       const auto lv = properties.fpTouchablePV << 
198       const auto polyhedron = lv->GetSolid()-> << 
199       if (polyhedron) {                        << 
200         polyhedron->SetVisAttributes(lv->GetVi << 
201         G4cout << "\nLocal polyhedron coordina << 
202         const G4Transform3D& transform = tempP << 
203         polyhedron->Transform(transform);      << 
204         G4cout << "\nGlobal polyhedron coordin << 
205       }                                        << 
206     } else {                                   << 
207       G4warn << "Touchable not found." << G4en << 
208     }                                          << 
209     return;                                    << 
210                                                << 
211   } else if (command == fpCommandFindPath) {   << 
212                                                << 
213     G4String pvName;                           << 
214     G4int copyNo;                              << 
215     std::istringstream iss(newValue);          << 
216     iss >> pvName >> copyNo;                   << 
217     std::vector<G4PhysicalVolumesSearchScene:: << 
218     std::vector<G4VPhysicalVolume*>::iterator  << 
219     transportationManager->GetWorldsIterator() << 
220     for (size_t i = 0; i < nWorlds; ++i, ++ite << 
221       G4PhysicalVolumeModel searchModel (*iter << 
222       G4ModelingParameters mp;  // Default - n << 
223       searchModel.SetModelingParameters (&mp); << 
224       // Find all instances at any position in << 
225       G4PhysicalVolumesSearchScene searchScene << 
226       searchModel.DescribeYourselfTo (searchSc << 
227       for (const auto& findings: searchScene.G << 
228         findingsVector.push_back(findings);    << 
229       }                                        << 
230     }                                          << 
231     for (const auto& findings: findingsVector) << 
232       G4cout                                   << 
233       <<  findings.fFoundBasePVPath            << 
234       << ' ' << findings.fpFoundPV->GetName()  << 
235       << ' ' <<  findings.fFoundPVCopyNo       << 
236       << " (mother logical volume: "           << 
237       << findings.fpFoundPV->GetMotherLogical( << 
238       << ')'                                   << 
239       << G4endl;                               << 
240     }                                          << 
241     if (findingsVector.size()) {               << 
242       G4cout                                   << 
243       << "Use this to set a particular touchab << 
244       << "\nor to see overlaps: \"/vis/drawLog << 
245       << G4endl;                               << 
246     } else {                                   << 
247       G4warn << pvName;                        << 
248       if (copyNo >= 0) G4warn << ':' << copyNo << 
249       G4warn << " not found" << G4endl;        << 
250     }                                          << 
251     return;                                    << 
252   }                                            << 
253                                                << 
254   G4VViewer* currentViewer = fpVisManager -> G    160   G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
255   if (!currentViewer) {                           161   if (!currentViewer) {
256     if (verbosity >= G4VisManager::errors) {      162     if (verbosity >= G4VisManager::errors) {
257       G4warn <<                                << 163       G4cerr <<
258       "ERROR: No current viewer - \"/vis/viewe    164       "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
259       << G4endl;                                  165       << G4endl;
260     }                                             166     }
261     return;                                       167     return;
262   }                                               168   }
263                                                   169 
264   G4Scene* currentScene = fpVisManager->GetCur    170   G4Scene* currentScene = fpVisManager->GetCurrentScene();
265   if (!currentScene) {                            171   if (!currentScene) {
266     if (verbosity >= G4VisManager::errors) {      172     if (verbosity >= G4VisManager::errors) {
267       G4warn <<                                << 173       G4cerr <<
268       "ERROR: No current scene - \"/vis/scene/    174       "ERROR: No current scene - \"/vis/scene/list\" to see possibilities."
269       << G4endl;                                  175       << G4endl;
270     }                                             176     }
271     return;                                       177     return;
272   }                                               178   }
273                                                   179 
274   if (command == fpCommandCentreOn || command     180   if (command == fpCommandCentreOn || command == fpCommandCentreAndZoomInOn) {
275                                                << 181     
276     // For twinkling...                        << 
277     std::vector<std::vector<G4PhysicalVolumeMo << 
278                                                << 
279     G4PhysicalVolumeModel::TouchableProperties    182     G4PhysicalVolumeModel::TouchableProperties properties =
280     G4TouchableUtils::FindTouchableProperties(    183     G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath);
281     if (properties.fpTouchablePV) {               184     if (properties.fpTouchablePV) {
282       // To handle parameterisations, set copy    185       // To handle parameterisations, set copy number
283       properties.fpTouchablePV->SetCopyNo(prop    186       properties.fpTouchablePV->SetCopyNo(properties.fCopyNo);
284       G4PhysicalVolumeModel tempPVModel           187       G4PhysicalVolumeModel tempPVModel
285       (properties.fpTouchablePV,                  188       (properties.fpTouchablePV,
286        G4PhysicalVolumeModel::UNLIMITED,          189        G4PhysicalVolumeModel::UNLIMITED,
287        properties.fTouchableGlobalTransform,      190        properties.fTouchableGlobalTransform,
288        nullptr, // Modelling parameters (not u    191        nullptr, // Modelling parameters (not used)
289        true, // use full extent (prevents calc    192        true, // use full extent (prevents calculating own extent, which crashes)
290        properties.fTouchableBaseFullPVPath);      193        properties.fTouchableBaseFullPVPath);
291       touchables.push_back(properties.fTouchab << 
292       // Use a temporary scene in order to fin    194       // Use a temporary scene in order to find vis extent
293       G4Scene tempScene("Centre Scene");          195       G4Scene tempScene("Centre Scene");
294       G4bool successful = tempScene.AddRunDura    196       G4bool successful = tempScene.AddRunDurationModel(&tempPVModel,warn);
295       if (!successful) return;                 << 197       if (successful) {
296       if (verbosity >= G4VisManager::parameter << 198         if (verbosity >= G4VisManager::confirmations) {
297         G4cout                                 << 199           G4cout
298         << "Touchable " << fCurrentTouchablePr << 200           << "Touchable " << fCurrentTouchableProperties.fTouchablePath
299         << ",\n  has been added to temporary s << 201           << ",\n  has been added to temporary scene \"" << tempScene.GetName() << "\"."
300         << G4endl;                             << 202           << G4endl;
                                                   >> 203         }
301       }                                           204       }
302                                                << 
303       const G4VisExtent& newExtent = tempScene    205       const G4VisExtent& newExtent = tempScene.GetExtent();
304       const G4ThreeVector& newTargetPoint = ne    206       const G4ThreeVector& newTargetPoint = newExtent.GetExtentCentre();
305       G4ViewParameters saveVP = currentViewer-    207       G4ViewParameters saveVP = currentViewer->GetViewParameters();
306       G4ViewParameters newVP = saveVP;            208       G4ViewParameters newVP = saveVP;
307       if (command == fpCommandCentreAndZoomInO    209       if (command == fpCommandCentreAndZoomInOn) {
308         // Calculate the new zoom factor          210         // Calculate the new zoom factor
309         const G4double zoomFactor                 211         const G4double zoomFactor
310         = currentScene->GetExtent().GetExtentR    212         = currentScene->GetExtent().GetExtentRadius()/newExtent.GetExtentRadius();
311         newVP.SetZoomFactor(zoomFactor);          213         newVP.SetZoomFactor(zoomFactor);
312       }                                           214       }
313       // Change the target point                  215       // Change the target point
314       const G4Point3D& standardTargetPoint = c    216       const G4Point3D& standardTargetPoint = currentScene->GetStandardTargetPoint();
315       newVP.SetCurrentTargetPoint(newTargetPoi    217       newVP.SetCurrentTargetPoint(newTargetPoint - standardTargetPoint);
316                                                << 
317       // Interpolate                              218       // Interpolate
318       auto keepVisVerbose = fpVisManager->GetV << 219       InterpolateToNewView(currentViewer, saveVP, newVP);
319       fpVisManager->SetVerboseLevel(G4VisManag << 
320       if (newVP != saveVP) InterpolateToNewVie << 
321       // ...and twinkle                        << 
322       Twinkle(currentViewer,newVP,touchables); << 
323       fpVisManager->SetVerboseLevel(keepVisVer << 
324                                                << 
325       if (verbosity >= G4VisManager::confirmat    220       if (verbosity >= G4VisManager::confirmations) {
326         G4cout                                    221         G4cout
327         << "Viewer \"" << currentViewer->GetNa    222         << "Viewer \"" << currentViewer->GetName()
328         << "\" centred ";                         223         << "\" centred ";
329         if (fpCommandCentreAndZoomInOn) {         224         if (fpCommandCentreAndZoomInOn) {
330           G4cout << "and zoomed in";              225           G4cout << "and zoomed in";
331         }                                         226         }
332         G4cout << " on touchable\n" << fCurren    227         G4cout << " on touchable\n" << fCurrentTouchableProperties.fTouchablePath
333         << G4endl;                                228         << G4endl;
334       }                                           229       }
335       SetViewParameters(currentViewer, newVP);    230       SetViewParameters(currentViewer, newVP);
336     } else {                                      231     } else {
337       G4warn << "Touchable not found." << G4en << 232       G4cout << "Touchable not found." << G4endl;
338     }                                             233     }
339     return;                                       234     return;
340                                                   235     
341   } else if (command == fpCommandDraw) {          236   } else if (command == fpCommandDraw) {
342                                                   237 
343     G4PhysicalVolumeModel::TouchableProperties    238     G4PhysicalVolumeModel::TouchableProperties properties =
344     G4TouchableUtils::FindTouchableProperties(    239     G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath);
345     if (properties.fpTouchablePV) {               240     if (properties.fpTouchablePV) {
346       // To handle parameterisations we have t << 241       // To handle paramaterisations we have to set the copy number
347       properties.fpTouchablePV->SetCopyNo(prop    242       properties.fpTouchablePV->SetCopyNo(properties.fCopyNo);
348       G4PhysicalVolumeModel* pvModel = new G4P    243       G4PhysicalVolumeModel* pvModel = new G4PhysicalVolumeModel
349       (properties.fpTouchablePV,                  244       (properties.fpTouchablePV,
350        G4PhysicalVolumeModel::UNLIMITED,          245        G4PhysicalVolumeModel::UNLIMITED,
351        properties.fTouchableGlobalTransform,      246        properties.fTouchableGlobalTransform,
352        nullptr, // Modelling parameters (not u    247        nullptr, // Modelling parameters (not used)
353        true, // use full extent (prevents calc    248        true, // use full extent (prevents calculating own extent, which crashes)
354        properties.fTouchableBaseFullPVPath);      249        properties.fTouchableBaseFullPVPath);
355                                                   250 
                                                   >> 251       G4int keepVerbose = UImanager->GetVerboseLevel();
                                                   >> 252       G4int newVerbose(0);
                                                   >> 253       if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
                                                   >> 254         newVerbose = 2;
                                                   >> 255       UImanager->SetVerboseLevel(newVerbose);
356       UImanager->ApplyCommand("/vis/scene/crea    256       UImanager->ApplyCommand("/vis/scene/create");
357       currentScene = fpVisManager->GetCurrentS    257       currentScene = fpVisManager->GetCurrentScene();  // New current scene
358       G4bool successful = currentScene->AddRun    258       G4bool successful = currentScene->AddRunDurationModel(pvModel,warn);
359       UImanager->ApplyCommand("/vis/sceneHandl    259       UImanager->ApplyCommand("/vis/sceneHandler/attach");
                                                   >> 260       UImanager->SetVerboseLevel(keepVerbose);
360                                                   261 
361       if (successful) {                           262       if (successful) {
362         if (fpCommandDraw->GetNewBoolValue(new << 
363           const auto& extent = pvModel->GetExt << 
364           const G4double halfX = (extent.GetXm << 
365           const G4double halfY = (extent.GetYm << 
366           const G4double halfZ = (extent.GetZm << 
367           G4Box extentBox("extent",halfX,halfY << 
368           G4VisAttributes extentVA;            << 
369           extentVA.SetForceWireframe();        << 
370           fpVisManager->Draw(extentBox,extentV << 
371         }                                      << 
372         if (verbosity >= G4VisManager::confirm    263         if (verbosity >= G4VisManager::confirmations) {
373           G4cout << "\"" << properties.fpTouch    264           G4cout << "\"" << properties.fpTouchablePV->GetName()
374           << "\", copy no. " << properties.fCo << 265           << "\", copy no. " << properties.fCopyNo << " drawn"
375           if (fpCommandDraw->GetNewBoolValue(n << 266           << G4endl;
376             G4cout << " with extent box";      << 
377           }                                    << 
378           G4cout << '.' << G4endl;             << 
379         }                                         267         }
380       } else {                                    268       } else {
381         G4VisCommandsSceneAddUnsuccessful(verb    269         G4VisCommandsSceneAddUnsuccessful(verbosity);
382       }                                           270       }
383     } else {                                      271     } else {
384       G4warn << "Touchable not found." << G4en << 272       G4cout << "Touchable not found." << G4endl;
                                                   >> 273     }
                                                   >> 274     return;
                                                   >> 275 
                                                   >> 276   } else if (command == fpCommandDump) {
                                                   >> 277 
                                                   >> 278     G4PhysicalVolumeModel::TouchableProperties properties =
                                                   >> 279     G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath);
                                                   >> 280     if (properties.fpTouchablePV) {
                                                   >> 281       // To handle paramaterisations we have to set the copy number
                                                   >> 282       properties.fpTouchablePV->SetCopyNo(properties.fCopyNo);
                                                   >> 283       G4PhysicalVolumeModel tempPVModel
                                                   >> 284       (properties.fpTouchablePV,
                                                   >> 285        G4PhysicalVolumeModel::UNLIMITED,
                                                   >> 286        properties.fTouchableGlobalTransform,
                                                   >> 287        nullptr, // Modelling parameters (not used)
                                                   >> 288        true, // use full extent (prevents calculating own extent, which crashes)
                                                   >> 289        properties.fTouchableBaseFullPVPath);
                                                   >> 290       const std::map<G4String,G4AttDef>* attDefs = tempPVModel.GetAttDefs();
                                                   >> 291       std::vector<G4AttValue>* attValues = tempPVModel.CreateCurrentAttValues();
                                                   >> 292       G4cout << G4AttCheck(attValues,attDefs);
                                                   >> 293       delete attValues;
                                                   >> 294       G4Polyhedron* polyhedron =
                                                   >> 295       properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetPolyhedron();
                                                   >> 296       G4cout << "\nLocal polyhedron coordinates:\n" << *polyhedron;
                                                   >> 297       G4Transform3D* transform = tempPVModel.GetCurrentTransform();
                                                   >> 298       polyhedron->Transform(*transform);
                                                   >> 299       G4cout << "\nGlobal polyhedron coordinates:\n" << *polyhedron;
                                                   >> 300     } else {
                                                   >> 301       G4cout << "Touchable not found." << G4endl;
385     }                                             302     }
386     return;                                       303     return;
387                                                   304 
388   } else if (command == fpCommandExtentForFiel    305   } else if (command == fpCommandExtentForField) {
389                                                   306 
390     G4PhysicalVolumeModel::TouchableProperties    307     G4PhysicalVolumeModel::TouchableProperties properties =
391     G4TouchableUtils::FindTouchableProperties(    308     G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath);
392     if (properties.fpTouchablePV) {               309     if (properties.fpTouchablePV) {
393       G4VisExtent extent                          310       G4VisExtent extent
394       = properties.fpTouchablePV->GetLogicalVo    311       = properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetExtent();
395       extent.Transform(properties.fTouchableGl    312       extent.Transform(properties.fTouchableGlobalTransform);
396       fCurrentExtentForField = extent;            313       fCurrentExtentForField = extent;
397       fCurrrentPVFindingsForField.clear();        314       fCurrrentPVFindingsForField.clear();
398       if (verbosity >= G4VisManager::confirmat    315       if (verbosity >= G4VisManager::confirmations) {
399         G4cout << "Extent for field set to " <    316         G4cout << "Extent for field set to " << extent
400         << "\nVolume for field has been cleare    317         << "\nVolume for field has been cleared."
401         << G4endl;                                318         << G4endl;
402       }                                           319       }
403       if (fpCommandExtentForField->GetNewBoolV    320       if (fpCommandExtentForField->GetNewBoolValue(newValue)) {
404         DrawExtent(extent);                       321         DrawExtent(extent);
405       }                                           322       }
406     } else {                                      323     } else {
407       G4warn << "Touchable not found." << G4en << 324       G4cout << "Touchable not found." << G4endl;
408     }                                             325     }
409     return;                                       326     return;
410                                                   327 
411   } else if (command == fpCommandLocalAxes) {  << 328   } else if (command == fpCommandFindPath) {
412                                                   329 
413     G4PhysicalVolumeModel::TouchableProperties << 330     G4String pvName;
414     G4TouchableUtils::FindTouchableProperties( << 331     G4int copyNo;
415     if (properties.fpTouchablePV) {            << 332     std::istringstream iss(newValue);
416       const auto& transform = fCurrentTouchabl << 333     iss >> pvName >> copyNo;
417       const auto& extent = fCurrentTouchablePr << 334     std::vector<G4PhysicalVolumesSearchScene::Findings> findingsVector;
418       const G4double lengthMax = extent.GetExt << 335     std::vector<G4VPhysicalVolume*>::iterator iterWorld =
419       const G4double intLog10LengthMax = std:: << 336     transportationManager->GetWorldsIterator();
420       G4double length = std::pow(10,intLog10Le << 337     for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
421       if (5.*length < lengthMax) length *= 5.; << 338       G4PhysicalVolumeModel searchModel (*iterWorld);  // Unlimited depth.
422       else if (2.*length < lengthMax) length * << 339       G4ModelingParameters mp;  // Default - no culling.
423       G4AxesModel axesModel(0.,0.,0.,length,tr << 340       searchModel.SetModelingParameters (&mp);
424       axesModel.SetGlobalTag("LocalAxesModel") << 341       G4PhysicalVolumesSearchScene searchScene (&searchModel, pvName, copyNo);
425       axesModel.DescribeYourselfTo(*fpVisManag << 342       searchModel.DescribeYourselfTo (searchScene);  // Initiate search.
426       G4UImanager::GetUIpointer()->ApplyComman << 343       for (const auto& findings: searchScene.GetFindings()) {
                                                   >> 344         findingsVector.push_back(findings);
                                                   >> 345       }
                                                   >> 346     }
                                                   >> 347     for (const auto& findings: findingsVector) {
                                                   >> 348       G4cout
                                                   >> 349       <<  findings.fFoundBasePVPath
                                                   >> 350       << ' ' << findings.fpFoundPV->GetName()
                                                   >> 351       << ' ' <<  findings.fFoundPVCopyNo
                                                   >> 352       << " (mother logical volume: "
                                                   >> 353       << findings.fpFoundPV->GetMotherLogical()->GetName()
                                                   >> 354       << ')'
                                                   >> 355       << G4endl;
                                                   >> 356     }
                                                   >> 357     if (findingsVector.size()) {
                                                   >> 358       G4cout
                                                   >> 359       << "Use this to set a particular touchable with \"/vis/set/touchable <path>\""
                                                   >> 360       << "\nor to see overlaps: \"/vis/drawLogicalVolume <mother-logical-volume-name>\""
                                                   >> 361       << G4endl;
427     } else {                                      362     } else {
428       G4warn << "Touchable not found." << G4en << 363       G4cout << pvName;
                                                   >> 364       if (copyNo >= 0) G4cout << ':' << copyNo;
                                                   >> 365       G4cout << " not found" << G4endl;
429     }                                             366     }
430     return;                                    << 
431                                                   367 
432   } else if (command == fpCommandShowExtent) {    368   } else if (command == fpCommandShowExtent) {
433                                                   369 
434     G4PhysicalVolumeModel::TouchableProperties    370     G4PhysicalVolumeModel::TouchableProperties properties =
435     G4TouchableUtils::FindTouchableProperties(    371     G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath);
436     if (properties.fpTouchablePV) {               372     if (properties.fpTouchablePV) {
437       G4VisExtent extent                          373       G4VisExtent extent
438       = properties.fpTouchablePV->GetLogicalVo    374       = properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetExtent();
439       extent.Transform(properties.fTouchableGl    375       extent.Transform(properties.fTouchableGlobalTransform);
440       G4cout << extent << G4endl;                 376       G4cout << extent << G4endl;
441       if (fpCommandShowExtent->GetNewBoolValue    377       if (fpCommandShowExtent->GetNewBoolValue(newValue)) DrawExtent(extent);
442     } else {                                      378     } else {
443       G4warn << "Touchable not found." << G4en << 379       G4cout << "Touchable not found." << G4endl;
444     }                                          << 
445     return;                                    << 
446                                                << 
447   } else if (command == fpCommandTwinkle) {    << 
448                                                << 
449     G4PhysicalVolumeModel::TouchableProperties << 
450     G4TouchableUtils::FindTouchableProperties( << 
451     if (properties.fpTouchablePV) {            << 
452       std::vector<std::vector<G4PhysicalVolume << 
453       touchables.push_back(properties.fTouchab << 
454       auto keepVisVerbose = fpVisManager->GetV << 
455       fpVisManager->SetVerboseLevel(G4VisManag << 
456       auto keepVP = currentViewer->GetViewPara << 
457       Twinkle(currentViewer,currentViewer->Get << 
458       SetViewParameters(currentViewer, keepVP) << 
459       fpVisManager->SetVerboseLevel(keepVisVer << 
460     } else {                                   << 
461       G4warn << "Touchable not found." << G4en << 
462     }                                             380     }
463     return;                                       381     return;
464                                                   382 
465   } else if (command == fpCommandVolumeForFiel    383   } else if (command == fpCommandVolumeForField) {
466                                                   384 
467     G4PhysicalVolumeModel::TouchableProperties    385     G4PhysicalVolumeModel::TouchableProperties properties =
468     G4TouchableUtils::FindTouchableProperties(    386     G4TouchableUtils::FindTouchableProperties(fCurrentTouchableProperties.fTouchablePath);
469     if (properties.fpTouchablePV) {               387     if (properties.fpTouchablePV) {
470       G4VisExtent extent                          388       G4VisExtent extent
471       = properties.fpTouchablePV->GetLogicalVo    389       = properties.fpTouchablePV->GetLogicalVolume()->GetSolid()->GetExtent();
472       extent.Transform(properties.fTouchableGl    390       extent.Transform(properties.fTouchableGlobalTransform);
473       fCurrentExtentForField = extent;            391       fCurrentExtentForField = extent;
474       fCurrrentPVFindingsForField.clear();        392       fCurrrentPVFindingsForField.clear();
475       fCurrrentPVFindingsForField.push_back       393       fCurrrentPVFindingsForField.push_back
476       (G4PhysicalVolumesSearchScene::Findings(    394       (G4PhysicalVolumesSearchScene::Findings(properties));
477       if (verbosity >= G4VisManager::confirmat    395       if (verbosity >= G4VisManager::confirmations) {
478         G4cout                                    396         G4cout
479         << "Volume for field set to " << prope    397         << "Volume for field set to " << properties.fpTouchablePV->GetName()
480         << ':' << properties.fCopyNo              398         << ':' << properties.fCopyNo
481         << " at " << properties.fTouchableBase    399         << " at " << properties.fTouchableBaseFullPVPath
482         << G4endl;                                400         << G4endl;
483       }                                           401       }
484       if (fpCommandVolumeForField->GetNewBoolV    402       if (fpCommandVolumeForField->GetNewBoolValue(newValue)) {
485         DrawExtent(extent);                       403         DrawExtent(extent);
486       }                                           404       }
487     } else {                                      405     } else {
488       G4warn << "Touchable not found." << G4en << 406       G4cout << "Touchable not found." << G4endl;
489     }                                             407     }
490     return;                                       408     return;
491                                                   409 
492   } else {                                        410   } else {
493                                                   411 
494     if (verbosity >= G4VisManager::errors) {      412     if (verbosity >= G4VisManager::errors) {
495       G4warn <<                                << 413       G4cerr <<
496       "ERROR: G4VisCommandsTouchable::SetNewVa    414       "ERROR: G4VisCommandsTouchable::SetNewValue: unrecognised command."
497       << G4endl;                                  415       << G4endl;
498     }                                             416     }
499     return;                                       417     return;
500   }                                               418   }
501 }                                                 419 }
502                                                   420