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3 ] [ 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/OpenInventor/src/G4OpenInventorXtExtendedViewer.cc (Version 11.3.0) and /visualization/OpenInventor/src/G4OpenInventorXtExtendedViewer.cc (Version 5.2.p2)


  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 /*                                                
 29  * jck 05 Feb 1997 - Initial Implementation       
 30  * jck 21 Apr 1997                                
 31  *  Mods for SoXtHepViewer                        
 32  * gb : on Win32 use an SoXtExaminerViewer.       
 33  * gb 05 April 2004 : revisit to separate Wind    
 34  * gb 09 November 2004 : restore the escape bu    
 35  * gb 09 November 2004 : have a menu bar in th    
 36  * gb 09 November 2004 : have gl2ps file produ    
 37  * gb 14 November 2004 : inherit G4OpenInvento    
 38  */                                               
 39                                                   
 40 // this :                                         
 41 #include "G4OpenInventorXtExtendedViewer.hh"      
 42                                                   
 43 #include <Inventor/nodes/SoSelection.h>           
 44                                                   
 45 #include <Inventor/Xt/SoXt.h>                     
 46                                                   
 47 //Replaces inclusion of SoXtExaminerViewer.h      
 48 #include <Inventor/Xt/viewers/SoXtFlyViewer.h>    
 49                                                   
 50 #include <X11/StringDefs.h>                       
 51 #include <X11/Shell.h>                            
 52                                                   
 53 #include <Xm/Xm.h>                                
 54 #include <Xm/PushB.h>                             
 55 #include <Xm/Form.h>                              
 56 #include <Xm/CascadeB.h>                          
 57 #include <Xm/RowColumn.h>                         
 58 #include <Xm/Text.h>                              
 59                                                   
 60 #include <cstdio>                                 
 61                                                   
 62 #include "HEPVis/actions/SoGL2PSAction.h"         
 63                                                   
 64 #include "G4OpenInventor.hh"                      
 65 #include "G4OpenInventorSceneHandler.hh"          
 66 #include "G4OpenInventorXtExaminerViewer.hh"      
 67 #include "G4VInteractorManager.hh"                
 68 #include "G4VisManager.hh"                        
 69 #include "G4AttCheck.hh"                          
 70                                                   
 71 G4OpenInventorXtExtendedViewer::G4OpenInventor    
 72  G4OpenInventorSceneHandler& sceneHandler         
 73 ,const G4String& name)                            
 74 :G4OpenInventorViewer (sceneHandler, name)        
 75 ,fShell(0)                                        
 76 ,fViewer(0)                                       
 77 ,fHelpForm(0)                                     
 78 ,fHelpText(0)                                     
 79 {                                                 
 80   if (G4VisManager::GetVerbosity() >= G4VisMan    
 81     G4cout << "Window name: " << fName << G4en    
 82 }                                                 
 83                                                   
 84                                                   
 85 void G4OpenInventorXtExtendedViewer::Initialis    
 86                                                   
 87   G4String wName = fName;                         
 88                                                   
 89   Widget parent = (Widget)fInteractorManager->    
 90   // G4cout << "DEBUG G4OpenInventorXtExtended    
 91   int width = 600;                                
 92   int height = 600;                               
 93                                                   
 94   if(!parent) {                                   
 95     // Check if user has specified an X-Window    
 96     char s[32];                                   
 97                                                   
 98     G4String sgeometry = fVP.GetXGeometryStrin    
 99     if(sgeometry.empty()) {                       
100       G4cout << "ERROR: Geometry string \""       
101              << sgeometry                         
102              << "\" is empty.  Using \"600x600    
103              << G4endl;                           
104       width = 600;                                
105       height = 600;                               
106       snprintf(s,32,"%dx%d",width,height);        
107       sgeometry = s;                              
108     } else {                                      
109       width = fVP.GetWindowSizeHintX();           
110       height = fVP.GetWindowSizeHintX();          
111     }                                             
112                                                   
113     //Create a shell window :                     
114     G4String shellName = wName;                   
115     shellName += "_shell";                        
116     Arg args[10];                                 
117     XtSetArg(args[0],XtNgeometry,XtNewString(s    
118     XtSetArg(args[1],XtNborderWidth,0);           
119     XtSetArg(args[2],XtNtitle,XtNewString(wNam    
120     fShell = XtAppCreateShell(shellName.c_str(    
121                topLevelShellWidgetClass,          
122              SoXt::getDisplay(),                  
123              args,3);                             
124                                                   
125     // G4cout << "DEBUG CREATING THE VIEWER WI    
126     fViewer = new G4OpenInventorXtExaminerView    
127     fViewer->addEscapeCallback(EscapeFromKeybo    
128                                                   
129     // FWJ (viewpoints don't work with this!)     
130     //    fViewer->setAutoClipping((SbBool)0);    
131                                                   
132     //XtSetArg(args[0],XmNtopAttachment   ,XmA    
133     //XtSetArg(args[1],XmNleftAttachment  ,XmA    
134     //XtSetArg(args[2],XmNrightAttachment ,XmA    
135     //XtSetArg(args[3],XmNbottomAttachment,XmA    
136     //Widget form = XmCreateForm (fShell,(char    
137     //XtManageChild (form);                       
138                                                   
139     Widget menuBar = fViewer->getMenuBar();       
140                                                   
141     //XtSetArg(args[0],XmNtopAttachment   ,XmA    
142     //XtSetArg(args[1],XmNleftAttachment  ,XmA    
143     //XtSetArg(args[2],XmNrightAttachment ,XmA    
144     //Widget menuBar = XmCreateMenuBar (form,(    
145     //XtManageChild(menuBar);                     
146                                                   
147    {Widget menu = fViewer->getMenu();             
148    //{Widget menu = AddMenu(menuBar,"File","Fi    
149     AddButton(menu,"Write PS (gl2ps)",PostScri    
150     AddButton(menu, "Write PDF (gl2ps)", PDFCb    
151     AddButton(menu,"Write PS (pixmap)",PixmapP    
152     AddButton(menu,"Write IV",WriteInventorCbk    
153     AddButton(menu,"Escape",EscapeCbk);}          
154                                                   
155    {Widget menu = AddMenu(menuBar,"Etc","Etc")    
156     AddButton(menu,"Erase detector",EraseDetec    
157     AddButton(menu,"Erase event",EraseEventCbk    
158     AddButton(menu,"Set solid",SetSolidCbk);      
159 /*    AddButton(menu,"Set (G4) wire frame",Set    
160     AddButton(menu,"Set (G4) reduced wire fram    
161     AddButton(menu,"Set (G4) full wire frame",    
162     AddButton(menu,"Visible mothers + invisibl    
163     AddButton(menu,"Visible mothers + visible     
164     AddButton(menu,"Update scene",UpdateSceneC    
165     AddButton(menu,"Scene graph stats",SceneGr    
166    }                                              
167                                                   
168    {Widget menu = AddMenu(menuBar,"Help","Help    
169     AddButton(menu,"Controls",HelpCbk);}          
170                                                   
171     //fViewer = new SoXtExaminerViewer(form,wN    
172                                                   
173     XtSetArg(args[0],XmNtopAttachment   ,XmATT    
174     XtSetArg(args[1],XmNtopWidget       ,menuB    
175     XtSetArg(args[2],XmNleftAttachment  ,XmATT    
176     XtSetArg(args[3],XmNrightAttachment ,XmATT    
177     XtSetArg(args[4],XmNbottomAttachment,XmATT    
178     XtSetValues(fViewer->getWidget(),args,5);     
179                                                   
180     fHelpForm = XmCreateFormDialog(fShell,(cha    
181     XtSetArg(args[0],XmNleftAttachment  ,XmATT    
182     XtSetArg(args[1],XmNrightAttachment ,XmATT    
183     XtSetArg(args[2],XmNbottomAttachment,XmATT    
184     Widget cancel = XmCreatePushButton(fHelpFo    
185     XtAddCallback(cancel,XmNactivateCallback,H    
186     XtManageChild(cancel);                        
187     XtSetArg(args[0],XmNtopAttachment   ,XmATT    
188     XtSetArg(args[1],XmNleftAttachment  ,XmATT    
189     XtSetArg(args[2],XmNrightAttachment ,XmATT    
190     XtSetArg(args[3],XmNbottomAttachment,XmATT    
191     XtSetArg(args[4],XmNbottomWidget    ,cance    
192     fHelpText = XmCreateScrolledText(fHelpForm    
193     XtManageChild(fHelpText);                     
194                                                   
195     fInteractorManager->AddShell(fShell);         
196                                                   
197   } else {                                        
198     char* str = fInteractorManager->GetCreatio    
199     if(str!=0) wName = str;                       
200     // G4cout << "DEBUG CREATING THE VIEWER WI    
201     fViewer = new G4OpenInventorXtExaminerView    
202   }                                               
203                                                   
204   // Use our own SelectionCB for the Xt viewer    
205   // when picking a trajectory                    
206   fSoSelection->removeSelectionCallback(G4Open    
207                                         this);    
208 //  fSoSelection->addSelectionCallback(Selecti    
209                                                   
210   fViewer->setSize(SbVec2s(width,height));        
211                                                   
212   // Have a GL2PS render action :                 
213   const SbViewportRegion& vpRegion = fViewer->    
214   fGL2PSAction = new SoGL2PSAction(vpRegion);     
215   fViewer->setGLRenderAction(fGL2PSAction);       
216                                                   
217   // Else :                                       
218   fViewer->setSceneGraph(fSoSelection);           
219   fViewer->viewAll();                             
220   fViewer->saveHomePosition();                    
221   fViewer->setTitle(fName);                       
222   fViewer->show();                                
223   if(fShell) {                                    
224     SoXt::show(fShell);                           
225     fInteractorManager->FlushAndWaitExecution     
226   }                                               
227   fInteractorManager->SetCreatedInteractor (fV    
228   // TJR added:                                   
229   fViewer->setTransparencyType(SoGLRenderActio    
230 }                                                 
231                                                   
232 G4OpenInventorXtExtendedViewer::~G4OpenInvento    
233   if(fShell) fInteractorManager->RemoveShell(f    
234   if(fViewer) {                                   
235     fViewer->setSceneGraph(0);                    
236     //FIXME : SGI : the below "delete" block t    
237     //FIXME : CoinXt : the below "delete" cras    
238     //FIXME : delete fViewer;                     
239   }                                               
240   if(fShell) XtDestroyWidget(fShell);             
241 }                                                 
242                                                   
243 void G4OpenInventorXtExtendedViewer::FinishVie    
244   if(!fViewer) return;                            
245   fViewer->viewAll();                             
246   fViewer->saveHomePosition();                    
247 }                                                 
248                                                   
249 void G4OpenInventorXtExtendedViewer::SetView (    
250   G4OpenInventorViewer::SetView ();               
251   if(!fViewer) return;                            
252   // Background.                                  
253   G4Colour b = fVP.GetBackgroundColour ();        
254   fViewer->setBackgroundColor                     
255     (SbColor((float)b.GetRed(),(float)b.GetGre    
256 }                                                 
257                                                   
258                                                   
259 void G4OpenInventorXtExtendedViewer::ViewerRen    
260   if(!fViewer) return;                            
261   fViewer->render();                              
262 }                                                 
263                                                   
264 SoCamera* G4OpenInventorXtExtendedViewer::GetC    
265   if(!fViewer) return 0;                          
266   return fViewer->getCamera();                    
267 }                                                 
268                                                   
269 Widget G4OpenInventorXtExtendedViewer::AddMenu    
270  Widget aMenuBar                                  
271 ,const G4String& aName                            
272 ,const G4String& aLabel                           
273 )                                                 
274 {                                                 
275   // Pulldown menu :                              
276   Widget menu = XmCreatePulldownMenu(aMenuBar,    
277   // Cascade button :                             
278   Arg args[2];                                    
279   XmString cps =                                  
280     XmStringLtoRCreate((char*)aLabel.c_str(),(    
281   XtSetArg (args[0],XmNlabelString,cps);          
282   XtSetArg (args[1],XmNsubMenuId,menu);           
283   Widget widget = XmCreateCascadeButton(aMenuB    
284   XmStringFree (cps);                             
285   XtManageChild(widget);                          
286   return menu;                                    
287 }                                                 
288 void G4OpenInventorXtExtendedViewer::AddButton    
289  Widget aMenu                                     
290 ,const G4String& aLabel                           
291 ,XtCallbackProc aCallback                         
292 )                                                 
293 {                                                 
294   Widget widget = XmCreatePushButton(aMenu,(ch    
295   XtManageChild(widget);                          
296   XtAddCallback(widget,XmNactivateCallback,aCa    
297 }                                                 
298                                                   
299 void G4OpenInventorXtExtendedViewer::HelpCance    
300   Widget,XtPointer aData,XtPointer) {             
301   G4OpenInventorXtExtendedViewer* This = (G4Op    
302   XtUnmanageChild(This->fHelpForm);               
303 }                                                 
304                                                   
305                                                   
306 //////////////////////////////////////////////    
307 //////////////////////////////////////////////    
308 //////////////////////////////////////////////    
309                                                   
310 void G4OpenInventorXtExtendedViewer::EscapeCbk    
311   Widget,XtPointer aData,XtPointer) {             
312   G4OpenInventorXtExtendedViewer* This = (G4Op    
313   This->Escape();                                 
314 }                                                 
315                                                   
316 // Allow escape from X event loop via key         
317 void G4OpenInventorXtExtendedViewer::EscapeFro    
318   G4OpenInventorXtExtendedViewer* This = (G4Op    
319   This->Escape();                                 
320 }                                                 
321                                                   
322 void G4OpenInventorXtExtendedViewer::PostScrip    
323   Widget,XtPointer aData,XtPointer) {             
324   G4OpenInventorXtExtendedViewer* This = (G4Op    
325   // FWJ Workaround: avoids empty 2nd page in     
326   SbBool superimpState =                          
327      This->fViewer->getSuperimpositionEnabled(    
328   This->fViewer->setSuperimpositionEnabled(Thi    
329                                            FAL    
330   This->WritePostScript();                        
331   if (superimpState)                              
332      This->fViewer->setSuperimpositionEnabled(    
333                                                   
334 }                                                 
335 void G4OpenInventorXtExtendedViewer::PDFCbk(      
336   Widget,XtPointer aData,XtPointer) {             
337   G4OpenInventorXtExtendedViewer* This = (G4Op    
338   // FWJ Workaround: avoids empty 2nd page in     
339   SbBool superimpState =                          
340      This->fViewer->getSuperimpositionEnabled(    
341   This->fViewer->setSuperimpositionEnabled(Thi    
342                                            FAL    
343   This->WritePDF();                               
344   if (superimpState)                              
345      This->fViewer->setSuperimpositionEnabled(    
346                                                   
347 }                                                 
348                                                   
349 void G4OpenInventorXtExtendedViewer::PixmapPos    
350   Widget,XtPointer aData,XtPointer) {             
351   G4OpenInventorXtExtendedViewer* This = (G4Op    
352   This->WritePixmapPostScript();                  
353 }                                                 
354                                                   
355 void G4OpenInventorXtExtendedViewer::SceneGrap    
356   Widget,XtPointer aData,XtPointer) {             
357   G4OpenInventorXtExtendedViewer* This = (G4Op    
358   This->SceneGraphStatistics();                   
359 }                                                 
360                                                   
361 void G4OpenInventorXtExtendedViewer::WriteInve    
362   Widget,XtPointer aData,XtPointer) {             
363   G4OpenInventorXtExtendedViewer* This = (G4Op    
364   This->WriteInventor();                          
365 }                                                 
366                                                   
367 void G4OpenInventorXtExtendedViewer::EraseDete    
368   Widget,XtPointer aData,XtPointer) {             
369   G4OpenInventorXtExtendedViewer* This = (G4Op    
370   This->EraseDetector();                          
371 }                                                 
372                                                   
373 void G4OpenInventorXtExtendedViewer::EraseEven    
374   Widget,XtPointer aData,XtPointer) {             
375   G4OpenInventorXtExtendedViewer* This = (G4Op    
376   This->EraseEvent();                             
377 }                                                 
378                                                   
379 void G4OpenInventorXtExtendedViewer::SetSolidC    
380   Widget,XtPointer aData,XtPointer) {             
381   G4OpenInventorXtExtendedViewer* This = (G4Op    
382   This->SetSolid();                               
383 }                                                 
384                                                   
385 void G4OpenInventorXtExtendedViewer::SetWireFr    
386   Widget,XtPointer aData,XtPointer) {             
387   G4OpenInventorXtExtendedViewer* This = (G4Op    
388   This->SetWireFrame();                           
389 }                                                 
390                                                   
391 void G4OpenInventorXtExtendedViewer::SetReduce    
392   Widget,XtPointer aData,XtPointer) {             
393   G4OpenInventorXtExtendedViewer* This = (G4Op    
394   This->SetReducedWireFrame(true);                
395 }                                                 
396                                                   
397 void G4OpenInventorXtExtendedViewer::SetFullWi    
398   Widget,XtPointer aData,XtPointer) {             
399   G4OpenInventorXtExtendedViewer* This = (G4Op    
400   This->SetReducedWireFrame(false);               
401 }                                                 
402                                                   
403 void G4OpenInventorXtExtendedViewer::UpdateSce    
404   Widget,XtPointer aData,XtPointer) {             
405   G4OpenInventorXtExtendedViewer* This = (G4Op    
406   This->UpdateScene();                            
407 }                                                 
408                                                   
409 void G4OpenInventorXtExtendedViewer::SetPrevie    
410   Widget,XtPointer aData,XtPointer) {             
411   G4OpenInventorXtExtendedViewer* This = (G4Op    
412   This->SetPreview();                             
413 }                                                 
414                                                   
415 void G4OpenInventorXtExtendedViewer::SetPrevie    
416   Widget,XtPointer aData,XtPointer) {             
417   G4OpenInventorXtExtendedViewer* This = (G4Op    
418   This->SetPreviewAndFull();                      
419 }                                                 
420                                                   
421 void G4OpenInventorXtExtendedViewer::HelpCbk(     
422   Widget,XtPointer aData,XtPointer) {             
423   G4OpenInventorXtExtendedViewer* This = (G4Op    
424   XtManageChild(This->fHelpForm);                 
425   XmTextSetString(This->fHelpText,(char*)This-    
426 }                                                 
427