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[ 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/OpenGL/src/G4OpenGLViewerMessenger.cc (Version 11.3.0) and /visualization/OpenGL/src/G4OpenGLViewerMessenger.cc (Version 4.0)


  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 "G4OpenGLViewerMessenger.hh"             
 29                                                   
 30 #include "G4OpenGLViewer.hh"                      
 31 #include "G4OpenGLStoredViewer.hh"                
 32 #include "G4OpenGLStoredSceneHandler.hh"          
 33 #include "G4UImanager.hh"                         
 34 #include "G4UIcommand.hh"                         
 35 #include "G4UIdirectory.hh"                       
 36 #include "G4UIcmdWithoutParameter.hh"             
 37 #include "G4UIcmdWithADouble.hh"                  
 38 #include "G4UIcmdWithABool.hh"                    
 39 #include "G4UIcmdWithAString.hh"                  
 40 #include "G4UIcmdWithAnInteger.hh"                
 41 #include "G4VisManager.hh"                        
 42 #include <sstream>                                
 43                                                   
 44 G4OpenGLViewerMessenger*                          
 45 G4OpenGLViewerMessenger::fpInstance = 0;          
 46                                                   
 47 G4OpenGLViewerMessenger*                          
 48 G4OpenGLViewerMessenger::GetInstance()            
 49 {                                                 
 50   if (!fpInstance) fpInstance = new G4OpenGLVi    
 51   return fpInstance;                              
 52 }                                                 
 53                                                   
 54 G4OpenGLViewerMessenger::G4OpenGLViewerMesseng    
 55 {                                                 
 56   G4bool omitable;                                
 57                                                   
 58   fpDirectory = new G4UIdirectory("/vis/ogl/")    
 59   fpDirectory->SetGuidance("G4OpenGLViewer com    
 60                                                   
 61   fpCommandExport =                               
 62   new G4UIcommand("/vis/ogl/export", this);       
 63   fpCommandExport->SetGuidance ("Export a scre    
 64   fpCommandExport->SetGuidance                    
 65   ("If name is \"\", filename and extension wi    
 66   fpCommandExport->SetGuidance                    
 67   ("If name is \"toto.png\", set the name to \    
 68   fpCommandExport->SetGuidance                    
 69   ("If name is \"toto\", set the name to \"tot    
 70   fpCommandExport->SetGuidance                    
 71   ("Will also add an incremented suffix at the    
 72    "\nthe same as previous it will not reset t    
 73   fpCommandExport->SetGuidance                    
 74   ("Setting size is available only on eps/pdf/    
 75   G4UIparameter* parameterExport;                 
 76   parameterExport = new G4UIparameter ("name",    
 77   parameterExport->SetDefaultValue("!");          
 78   parameterExport->SetGuidance                    
 79   ("By default, will take a default value or t    
 80    " value if set.");                             
 81   fpCommandExport->SetParameter(parameterExpor    
 82   parameterExport = new G4UIparameter ("width"    
 83   parameterExport->SetGuidance                    
 84   ("By default, will take the current width of    
 85    "\nif set. This parameter is only useful fo    
 86   parameterExport->SetDefaultValue(-1);           
 87   fpCommandExport->SetParameter(parameterExpor    
 88   parameterExport = new G4UIparameter ("height    
 89   parameterExport->SetGuidance                    
 90   ("By default, will take the current height o    
 91    "\nif set. This parameter is only useful fo    
 92   parameterExport->SetDefaultValue(-1);           
 93   fpCommandExport->SetParameter(parameterExpor    
 94                                                   
 95   fpCommandFlushAt = new G4UIcommand("/vis/ogl    
 96   fpCommandFlushAt->SetGuidance                   
 97   ("Controls the rate at which graphics primit    
 98   fpCommandFlushAt->SetGuidance                   
 99   ("Flushing to screen is an expensive operati    
100    "\nan action suitable for your application.    
101    "\nto screen anyway at end of drawing, and     
102    "\nanyway depending on /vis/scene/endOfEven    
103   fpCommandFlushAt->SetGuidance                   
104   ("For NthPrimitive and NthEvent the second p    
105   fpCommandFlushAt->SetGuidance                   
106   ("For \"never\", detectors and events are st    
107   G4UIparameter* parameterFlushAt;                
108   parameterFlushAt = new G4UIparameter ("actio    
109   parameterFlushAt->SetParameterCandidates        
110   ("endOfEvent endOfRun eachPrimitive NthPrimi    
111   parameterFlushAt->SetDefaultValue("NthEvent"    
112   fpCommandFlushAt->SetParameter(parameterFlus    
113   parameterFlushAt = new G4UIparameter ("N", '    
114   parameterFlushAt->SetDefaultValue(100);         
115   fpCommandFlushAt->SetParameter(parameterFlus    
116                                                   
117   fpDirectorySet = new G4UIdirectory ("/vis/og    
118   fpDirectorySet->SetGuidance("G4OpenGLViewer     
119                                                   
120   fpCommandDisplayListLimit =                     
121     new G4UIcmdWithoutParameter("/vis/ogl/set/    
122   fpCommandDisplayListLimit->SetGuidance          
123   ("This command is no longer relevant. There     
124    "\nnumber of display lists - except, of cou    
125    "\nyour computer. Keep an eye on that. Good    
126                                                   
127   fpCommandExportFormat =                         
128   new G4UIcommand("/vis/ogl/set/exportFormat",    
129   fpCommandExportFormat->SetGuidance ("Set exp    
130   fpCommandExportFormat->SetGuidance ("By defa    
131   fpCommandExportFormat->SetGuidance ("Try /vi    
132   fpCommandExportFormat->SetGuidance ("Changin    
133   G4UIparameter* parameterExportFormat;           
134   parameterExportFormat = new G4UIparameter ("    
135   parameterExportFormat->SetDefaultValue("");     
136   fpCommandExportFormat->SetParameter(paramete    
137                                                   
138   fpCommandPrintFilename =                        
139     new G4UIcommand("/vis/ogl/set/printFilenam    
140   fpCommandPrintFilename->SetGuidance ("Set pr    
141   fpCommandPrintFilename->SetGuidance ("Settin    
142   G4UIparameter* parameterPrintFilename;          
143   parameterPrintFilename = new G4UIparameter (    
144   parameterPrintFilename->SetDefaultValue("G4O    
145   fpCommandPrintFilename->SetParameter(paramet    
146   parameterPrintFilename = new G4UIparameter (    
147   parameterPrintFilename->SetDefaultValue(1);     
148   fpCommandPrintFilename->SetParameter(paramet    
149                                                   
150   fpCommandPrintMode = new G4UIcmdWithAString(    
151   fpCommandPrintMode->SetGuidance("Set print m    
152   fpCommandPrintMode->SetParameterName("print_    
153   fpCommandPrintMode->SetCandidates("vectored     
154   fpCommandPrintMode->SetDefaultValue("vectore    
155                                                   
156   fpCommandPrintSize =                            
157     new G4UIcommand("/vis/ogl/set/printSize",     
158   fpCommandPrintSize->SetGuidance ("Set print     
159   fpCommandPrintSize->SetGuidance ("Tip : -1 w    
160   fpCommandPrintSize->SetGuidance ("       Set    
161   G4UIparameter* parameterPrintSize;              
162   parameterPrintSize = new G4UIparameter ("wid    
163   parameterPrintSize->SetDefaultValue(-1);        
164   fpCommandPrintSize->SetParameter(parameterPr    
165   parameterPrintSize = new G4UIparameter ("hei    
166   parameterPrintSize->SetDefaultValue(-1);        
167   fpCommandPrintSize->SetParameter(parameterPr    
168                                                   
169   fpCommandTransparency =                         
170     new G4UIcmdWithABool("/vis/ogl/set/transpa    
171   fpCommandTransparency->SetGuidance              
172     ("True/false to enable/disable rendering o    
173   fpCommandTransparency->SetParameterName         
174     ("transparency-enabled", omitable = true);    
175   fpCommandTransparency->SetDefaultValue(true)    
176 }                                                 
177                                                   
178 G4OpenGLViewerMessenger::~G4OpenGLViewerMessen    
179 {                                                 
180   delete fpCommandTransparency;                   
181   delete fpCommandPrintSize;                      
182   delete fpCommandPrintMode;                      
183   delete fpCommandPrintFilename;                  
184   delete fpCommandExportFormat;                   
185   delete fpCommandDisplayListLimit;               
186   delete fpDirectorySet;                          
187   delete fpCommandFlushAt;                        
188   delete fpCommandExport;                         
189   delete fpDirectory;                             
190                                                   
191   delete fpInstance;                              
192 }                                                 
193                                                   
194 void G4OpenGLViewerMessenger::SetNewValue         
195 (G4UIcommand* command, G4String newValue)         
196 {                                                 
197   G4VisManager* pVisManager = G4VisManager::Ge    
198                                                   
199   G4VViewer* pViewer = pVisManager->GetCurrent    
200   if (!pViewer) {                                 
201     G4cout <<                                     
202       "G4OpenGLViewerMessenger::SetNewValue: N    
203       "\n  \"/vis/open\", or similar, to get o    
204            << G4endl;                             
205     return;                                       
206   }                                               
207                                                   
208   G4VSceneHandler* pSceneHandler = pViewer->Ge    
209   if (!pSceneHandler) {                           
210     G4cout <<                                     
211     "G4OpenGLViewerMessenger::SetNewValue: Thi    
212     "\n  Shouldn't happen - please report circ    
213     "\n  (Viewer is \"" << pViewer->GetName()     
214     "\n  Try \"/vis/open\", or similar, to get    
215     << G4endl;                                    
216     return;                                       
217   }                                               
218                                                   
219   G4OpenGLViewer* pOGLViewer = dynamic_cast<G4    
220   if (!pOGLViewer) {                              
221     G4cout <<                                     
222       "G4OpenGLViewerMessenger::SetNewValue: C    
223       "\n  OGL.  (It is \""                       
224      << pViewer->GetName() <<                     
225       "\".)\n  Use \"/vis/viewer/select\" or \    
226            << G4endl;                             
227     return;                                       
228   }                                               
229                                                   
230   G4OpenGLSceneHandler* pOGLSceneHandler =        
231   dynamic_cast<G4OpenGLSceneHandler*>(pSceneHa    
232   if (!pOGLSceneHandler) {                        
233     G4cout <<                                     
234     "G4OpenGLViewerMessenger::SetNewValue: Cur    
235     "\n  OGL.  (Viewer is \"" << pViewer->GetN    
236     "\n  (Scene handler is \"" << pSceneHandle    
237     "\n  Use \"/vis/sceneHandler/list\" and \"    
238     "\n  or \"/vis/open\"."                       
239     << G4endl;                                    
240     return;                                       
241   }                                               
242                                                   
243   if (command == fpCommandExport)                 
244   {                                               
245     G4String name;                                
246     G4int width,height;                           
247     std::istringstream iss(newValue);             
248     iss >> name >> width >> height;               
249     pOGLViewer->exportImage(name, width, heigh    
250                                                   
251     if (pOGLViewer->fVP.IsAutoRefresh())          
252       G4UImanager::GetUIpointer()->ApplyComman    
253     return;                                       
254   }                                               
255                                                   
256   if (command == fpCommandExportFormat)           
257   {                                               
258     G4String name;                                
259     std::istringstream iss(newValue);             
260     iss >> name;                                  
261     pOGLViewer->setExportImageFormat(name);       
262                                                   
263     return;                                       
264   }                                               
265                                                   
266   if (command == fpCommandFlushAt)                
267   {                                               
268     static G4bool firstTime = true;               
269     static std::map<G4String,G4OpenGLSceneHand    
270     if (firstTime) {                              
271       actionMap["endOfEvent"]    = G4OpenGLSce    
272       actionMap["endOfRun"]      = G4OpenGLSce    
273       actionMap["eachPrimitive"] = G4OpenGLSce    
274       actionMap["NthPrimitive"]  = G4OpenGLSce    
275       actionMap["NthEvent"]      = G4OpenGLSce    
276       actionMap["never"]         = G4OpenGLSce    
277       firstTime = false;                          
278     }                                             
279     G4String action;                              
280     G4int entitiesFlushInterval;                  
281     std::istringstream iss(newValue);             
282     iss >> action >> entitiesFlushInterval;       
283     pOGLSceneHandler->SetFlushAction(actionMap    
284     pOGLSceneHandler->SetEntitiesFlushInterval    
285     return;                                       
286   }                                               
287                                                   
288   if (command == fpCommandPrintFilename)          
289     {                                             
290       G4String name;                              
291       G4bool inc;                                 
292       std::istringstream iss(newValue);           
293       iss >> name                                 
294     >> inc;                                       
295       pOGLViewer->setExportFilename(name,inc);    
296       return;                                     
297     }                                             
298                                                   
299   if (command == fpCommandPrintMode)              
300     {                                             
301       if (newValue == "vectored") pOGLViewer->    
302                                                   
303       if (newValue == "pixmap") pOGLViewer->fV    
304       return;                                     
305     }                                             
306                                                   
307   if (command == fpCommandPrintSize)              
308     {                                             
309       G4int width,height;                         
310       std::istringstream iss(newValue);           
311       iss >> width                                
312     >> height;                                    
313       pOGLViewer->setExportSize(width,height);    
314       return;                                     
315     }                                             
316                                                   
317   if (command == fpCommandTransparency)           
318     {                                             
319       pOGLViewer->transparency_enabled = comma    
320       if (pOGLViewer->fVP.IsAutoRefresh())        
321   G4UImanager::GetUIpointer()->ApplyCommand("/    
322       return;                                     
323     }                                             
324                                                   
325   // Stored viewer commands                       
326   G4OpenGLStoredViewer* pOGLSViewer =             
327     dynamic_cast<G4OpenGLStoredViewer*>(pViewe    
328                                                   
329   if (!pOGLSViewer)                               
330     {                                             
331       G4cout <<                                   
332   "G4OpenGLViewerMessenger::SetNewValue: Curre    
333   "\n  (It is \"" << pViewer->GetName() << "\"    
334   "\n  This feature is only implemented for OG    
335   "\n  Use \"/vis/viewer/select\" or \"/vis/op    
336        << G4endl;                                 
337       return;                                     
338     }                                             
339                                                   
340   // Scene handler commands                       
341   G4OpenGLStoredSceneHandler* pOGLSSceneHandle    
342     dynamic_cast<G4OpenGLStoredSceneHandler*>(    
343                                                   
344   if (!pOGLSSceneHandler) {                       
345     G4cout <<                                     
346   "G4OpenGLViewerMessenger::SetNewValue: Curre    
347   "\n  OGLS (Stored).  (Viewer is \"" << pView    
348   "\n  (Scene handler is \"" << pSceneHandler-    
349   "\n  This feature is only implemented for OG    
350   "\n  scene handlers.  Use \"/vis/viewer/sele    
351            << G4endl;                             
352     return;                                       
353   }                                               
354                                                   
355   if (command == fpCommandDisplayListLimit)       
356     {                                             
357       G4cerr << command->GetGuidanceLine(0) <<    
358       return;                                     
359     }                                             
360 }                                                 
361