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] [ 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 /graphics_reps/src/G4SceneTreeItem.cc (Version 11.3.0) and /graphics_reps/src/G4SceneTreeItem.cc (Version 4.0.p1)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27                                                   
 28 #include "G4SceneTreeItem.hh"                     
 29                                                   
 30 #include "G4AttCheck.hh"                          
 31                                                   
 32 #include <iostream>                               
 33                                                   
 34 // A ghost is a touchable we know to be there     
 35 std::map<G4SceneTreeItem::Type, G4String> G4Sc    
 36   {G4SceneTreeItem::unidentified, "unidentifie    
 37   {G4SceneTreeItem::root, "root"},                
 38   {G4SceneTreeItem::ghost, "ghost"},              
 39   {G4SceneTreeItem::model, "model"},              
 40   {G4SceneTreeItem::pvmodel, "pvmodel"},          
 41   {G4SceneTreeItem::touchable, "touchable"}};     
 42                                                   
 43 // Reset visibility of all objects to false -     
 44 void G4SceneTreeItem::ResetVisibility()           
 45 {                                                 
 46   // Reset all but the root item, which is alw    
 47   // Other items will be set visible if and wh    
 48   if (fType != root) fVisAttributes.SetVisibil    
 49   for (auto& child : fChildren)                   
 50     child.ResetVisibility();                      
 51 }                                                 
 52                                                   
 53 // If found, returns "true" and places iterato    
 54 G4bool G4SceneTreeItem::FindTouchableFromRoot(    
 55                                                   
 56 {                                                 
 57   if (fType != root) {                            
 58     G4ExceptionDescription ed;                    
 59     ed << "Not a root item:\n";                   
 60     DumpSingleItem(ed);                           
 61     G4Exception("G4SceneTreeItem::FindTouchabl    
 62     return false;                                 
 63   }                                               
 64                                                   
 65   for (auto& aModel : fChildren) {                
 66     if (aModel.fModelType == "G4PhysicalVolume    
 67       // Work down the path - "name id", then     
 68       G4String partialPathString;                 
 69       auto iter = aModel.fChildren.begin();       
 70       auto iterEnd = aModel.fChildren.end();      
 71       std::istringstream iss(fullPathString);     
 72       G4String name, copyNo;                      
 73       while (iss >> name >> copyNo) {             
 74         partialPathString += ' ' + name + ' '     
 75         for (; iter != iterEnd; ++iter) {         
 76           if (iter->fPVPath == partialPathStri    
 77             if (partialPathString != fullPathS    
 78               // Go to next level                 
 79               iter = iter->fChildren.begin();     
 80               iterEnd = iter->fChildren.end();    
 81             }                                     
 82             break;                                
 83           }                                       
 84         }                                         
 85         if (iter != iterEnd) {  // Found          
 86           foundIter = iter;                       
 87           return true;                            
 88         }                                         
 89       }                                           
 90     }                                             
 91   }                                               
 92   return false;                                   
 93 }                                                 
 94                                                   
 95 // Dump single item, i.e., ignore any children    
 96 void G4SceneTreeItem::DumpSingleItem(std::ostr    
 97 {                                                 
 98   static G4bool first = true;                     
 99   if (first) {                                    
100     first = false;                                
101     os << "  Verbosity actions:"                  
102        << "\n  >=0 one line"                      
103        << "\n  >=1 a few lines"                   
104        << "\n  >=2 check G4Atts"                  
105        << "\n  >=3 print G4Atts"                  
106        << "\n  >=4 print some attValues"          
107        << '\n';                                   
108   }                                               
109                                                   
110   os << GetTypeString() << " (";                  
111   G4String status;                                
112   switch (fType) {                                
113     case unidentified:                            
114       status = "error";                           
115       break;                                      
116     case root:                                    
117       status = "active";                          
118       break;                                      
119     case model:                                   
120       [[fallthrough]];                            
121     case pvmodel:                                 
122       status = (fVisAttributes.IsVisible() ? "    
123       break;                                      
124     case ghost:                                   
125       [[fallthrough]];                            
126     case touchable:                               
127       status = (fVisAttributes.IsVisible() ? "    
128       break;                                      
129   }                                               
130   if (fExpanded) {                                
131     status += ",expanded";                        
132   } else {                                        
133     status += ",collapsed";                       
134   }                                               
135   os << status << ')';                            
136                                                   
137   G4String description;                           
138   switch (fType) {                                
139     case unidentified:                            
140       break;                                      
141     case root:                                    
142       break;                                      
143     case model:                                   
144       [[fallthrough]];                            
145     case pvmodel:                                 
146       description = " \"" + fModelDescription     
147       break;                                      
148     case ghost:                                   
149       [[fallthrough]];                            
150     case touchable:                               
151       description = " (" + fPVPath.substr(1, f    
152       break;                                      
153   }                                               
154   os << description;                              
155                                                   
156   if (fType == touchable) {                       
157     os << ' ' << fVisAttributes.GetColour();      
158   }                                               
159                                                   
160   // clang-format off                             
161   if (verbosity >= 1) {                           
162     os << "\n  Description: " << GetDescriptio    
163     << "\n  Model type: " << GetModelType()       
164     << "\n  Model description: " << GetModelDe    
165     << "\n  " << fChildren.size() << (fChildre    
166   }                                               
167   // clang-format on                              
168                                                   
169   if (verbosity >= 2) {                           
170     const auto& attDefs = GetAttDefs();           
171     const auto& attValues = GetAttValues();       
172     if (attDefs == nullptr || attValues == nul    
173       os << "\n  No G4Atts";  // Legitimate       
174     }                                             
175     else {                                        
176       G4AttCheck attCheck(attValues, attDefs);    
177       if (attCheck.Check("G4SceneTreeItem::Dum    
178         G4ExceptionDescription ed;                
179         ed << "Item: " << attCheck;               
180         G4Exception("G4SceneTreeItem::Dump", "    
181                     "G4Atts don't check out");    
182         return;                                   
183       }                                           
184                                                   
185       if (verbosity >= 3) {                       
186         os << "\n  G4Atts:\n" << attCheck;        
187         static G4bool first1 = true;              
188         if (first1) {                             
189           first1 = false;                         
190           os << "\n  Available G4Atts for touc    
191           // clang-format off                     
192           for (const auto& att: *GetAttDefs())    
193             os << "\n  " << att.first             
194             << ',' << att.second.GetName()        
195             << ',' << att.second.GetDesc()        
196             << ',' << att.second.GetCategory()    
197             << ',' << att.second.GetExtra()       
198             << ',' << att.second.GetValueType(    
199             << ',' << att.second.GetTypeKey();    
200           }                                       
201           // clang-format on                      
202           os << '\n';                             
203         }                                         
204       }                                           
205                                                   
206       if (verbosity >= 4) {                       
207         for (G4String name : {"PVPath", "Globa    
208           G4String result;                        
209           const auto& iterAttDef = attDefs->fi    
210           if (iterAttDef != attDefs->end()) {     
211             result = result + "\n  " + iterAtt    
212             result = result + ", " + iterAttDe    
213           }                                       
214           const G4AttValue* pAttValue = nullpt    
215           for (const auto& attValue : *attValu    
216             // Why are the attValues not in a     
217             if (attValue.GetName() == name) {     
218               pAttValue = &attValue;  // Avoid    
219               break;                              
220             }                                     
221           }                                       
222           if (pAttValue) {                        
223             result = result + ", " + pAttValue    
224           }                                       
225                                                   
226           os << result;                           
227         }                                         
228       }                                           
229     }                                             
230   }                                               
231                                                   
232   os << std::endl;                                
233 }                                                 
234                                                   
235 // Dump whole tree                                
236 void G4SceneTreeItem::DumpTree(std::ostream& o    
237 {                                                 
238   static G4int depth = 0;                         
239   for (G4int i = 0; i < depth; i++) os << "  "    
240   DumpSingleItem(os, verbosity);                  
241   for (auto& child : GetChildren()) {             
242     depth++;                                      
243     child.DumpTree(os, verbosity);                
244     depth--;                                      
245   }                                               
246 }                                                 
247