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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/OpenInventor/src/G4OpenInventorQtViewer.cc (Version 11.3.0) and /visualization/OpenInventor/src/G4OpenInventorQtViewer.cc (Version 10.3.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 // Frederick Jones TRIUMF 07 November 2017        
 27                                                   
 28 // this :                                         
 29 #include "G4OpenInventorQtViewer.hh"              
 30                                                   
 31 #include "G4OpenInventorQtExaminerViewer.hh"      
 32                                                   
 33 #include <Inventor/nodes/SoSelection.h>           
 34                                                   
 35 #include <Inventor/Qt/SoQt.h>                     
 36 // FWJ these are needed (why?) to use flags in    
 37 #include <Inventor/Qt/viewers/SoQtViewer.h>       
 38 #include <Inventor/Qt/viewers/SoQtFullViewer.h    
 39 #include <Inventor/Qt/viewers/SoQtExaminerView    
 40                                                   
 41 //#include <QMenuBar>                             
 42 #include <QMenu>                                  
 43 #include <QAction>                                
 44 #include <QFont>                                  
 45                                                   
 46 #include "HEPVis/actions/SoGL2PSAction.h"         
 47                                                   
 48 #include "G4OpenInventor.hh"                      
 49 #include "G4OpenInventorSceneHandler.hh"          
 50 #include "G4VInteractorManager.hh"                
 51 #include "G4VisManager.hh"                        
 52 #include "G4UImanager.hh"                         
 53 #include "G4UIQt.hh"                              
 54                                                   
 55 #include "G4SoQt.hh"                              
 56                                                   
 57 #ifndef G4GMAKE                                   
 58 #include "moc_G4OpenInventorQtViewer.cpp"         
 59 #endif                                            
 60                                                   
 61 G4OpenInventorQtViewer::G4OpenInventorQtViewer    
 62    G4OpenInventorSceneHandler& sceneHandler, c    
 63    : G4OpenInventorViewer(sceneHandler, name),    
 64 #if 0x060000 <= QT_VERSION                        
 65    ,fDestroyCallback(0)                           
 66 #endif                                            
 67 {                                                 
 68 #if 0x060000 <= QT_VERSION                        
 69   fDestroyCallback = new G4OpenInventorQtDestr    
 70 #endif                                            
 71    // FWJ fName is in G4VViewer parent of G4Op    
 72    if (G4VisManager::GetVerbosity() >= G4VisMa    
 73      G4cout << "Window name: " << fName << G4e    
 74 }                                                 
 75                                                   
 76                                                   
 77 void G4OpenInventorQtViewer::Initialise()         
 78 {                                                 
 79                                                   
 80 #if QT_VERSION < 0x060000                         
 81    QWidget* parent = SoQt::getTopLevelWidget()    
 82 #else                                             
 83    QWidget* parent = new QWidget;                 
 84    QObject::connect(parent,SIGNAL(destroyed())    
 85 #endif                                            
 86                                                   
 87    // FWJ DEBUG                                   
 88    //  G4cout << "G4OIQtViewer: Creating G4OIQ    
 89    //     parent << G4endl;                       
 90                                                   
 91    fViewer = new G4OpenInventorQtExaminerViewe    
 92                                                   
 93 #if 0x060000 <= QT_VERSION                        
 94    fViewer->addInTab();                           
 95 #endif                                            
 96                                                   
 97    // FWJ tried this to replace sensors, but i    
 98    //   fGroupCameraSensor->detach();             
 99    //   fCameraSensor->detach();                  
100    //   fViewer->addFinishCallback(FinishCB);     
101                                                   
102    auto UI = G4UImanager::GetUIpointer();         
103    auto uiQt = dynamic_cast<G4UIQt*>(UI->GetG4    
104                                                   
105    // Moved this to G4OpenInventorQtExaminerVi    
106    ///////////////////////////////////////////    
107    //                                             
108    // This explicitly sets the TabWidget as pa    
109    //   if (uiQt) uiQt->AddTabWidget(parent, Q    
110    ///////////////////////////////////////////    
111                                                   
112    // Simpler: calls addTab(), but causes view    
113    // in the "Useful tips" page !!                
114    //   if (uiQt) uiQt->AddViewerTab(parent, f    
115    // Leaves an empty viewer window frame hang    
116    //   if (uiQt) uiQt->AddTabWidget(fViewer->    
117                                                   
118    //  G4String wName = fName;                    
119    //                                             
120    //  QWidget parent = (QWidget)fInteractorMa    
121                                                   
122 #if QT_VERSION < 0x060000                         
123    int width = fVP.GetWindowSizeHintX();          
124    int height = fVP.GetWindowSizeHintY();         
125                                                   
126    // FWJ not sure what this is for               
127    //     fInteractorManager->AddShell(fShell)    
128                                                   
129    // FWJ or this:                                
130    //   } else {                                  
131    //    char* str = fInteractorManager->GetCr    
132    //    if(str!=0) wName = str;                  
133    //    fViewer = new SoQtExaminerViewer(pare    
134    //  }                                          
135                                                   
136    fViewer->setSize(SbVec2s(width, height));      
137    fViewer->setOrigWindowSize(width, height);     
138 #else                                             
139    //G.Barrand: if in a QTabViewer, it is bett    
140    //           SoQt set the size and position    
141 #endif                                            
142                                                   
143    // Add common menu items...                    
144                                                   
145    //   QMenuBar* menubar = fViewer->getMenuba    
146    QMenu* filemenu = fViewer->getFileMenu();      
147    QMenu* etcmenu = fViewer->getEtcMenu();        
148    QFont* font = fViewer->getFont();              
149                                                   
150    // File menu                                   
151                                                   
152    FileWritePS = new QAction("Write PostScript    
153    FileWritePS->setFont(*font);                   
154    connect(FileWritePS, SIGNAL(triggered()), t    
155            SLOT(FileWritePSCB()));                
156    filemenu->addAction(FileWritePS);              
157                                                   
158    FileWritePDF = new QAction("Write PDF (gl2p    
159    FileWritePDF->setFont(*font);                  
160    connect(FileWritePDF, SIGNAL(triggered()),     
161            SLOT(FileWritePDFCB()));               
162    filemenu->addAction(FileWritePDF);             
163                                                   
164    FileWriteIV = new QAction("Write IV", this)    
165    FileWriteIV->setFont(*font);                   
166    connect(FileWriteIV, SIGNAL(triggered()), t    
167            SLOT(FileWriteIVCB()));                
168    filemenu->addAction(FileWriteIV);              
169                                                   
170    FileEscape = new QAction("Escape", this);      
171    FileEscape->setFont(*font);                    
172    connect(FileEscape, SIGNAL(triggered()), th    
173            SLOT(FileEscapeCB()));                 
174    filemenu->addAction(FileEscape);               
175                                                   
176    //   G4cout << "G4OIQtViewer: externalApp =    
177    //   static_cast<G4SoQt*>(fInteractorManage    
178    if (static_cast<G4SoQt*>(fInteractorManager    
179       fViewer->setExternalQtApp();                
180                                                   
181    // Register escape CB with viewer, allowing    
182    //   fViewer->addEscapeCallback(FileEscapeC    
183    //   fViewer->addEscapeCallback(FileEscapeC    
184                                                   
185    // Etc menu                                    
186                                                   
187    EtcEraseDetector = new QAction("Erase detec    
188    EtcEraseDetector->setFont(*font);              
189    connect(EtcEraseDetector, SIGNAL(triggered(    
190            SLOT(EtcEraseDetectorCB()));           
191    etcmenu->addAction(EtcEraseDetector);          
192                                                   
193    EtcEraseEvent = new QAction("Erase event",     
194    EtcEraseEvent->setFont(*font);                 
195    connect(EtcEraseEvent, SIGNAL(triggered()),    
196            SLOT(EtcEraseEventCB()));              
197    etcmenu->addAction(EtcEraseEvent);             
198                                                   
199    EtcSetSolid = new QAction("Set solid", this    
200    EtcSetSolid->setFont(*font);                   
201    connect(EtcSetSolid, SIGNAL(triggered()), t    
202    etcmenu->addAction(EtcSetSolid);               
203                                                   
204    EtcSetReducedWireframe = new QAction("Set (    
205    EtcSetReducedWireframe->setFont(*font);        
206    connect(EtcSetReducedWireframe, SIGNAL(trig    
207            SLOT(EtcSetReducedWireframeCB()));     
208    etcmenu->addAction(EtcSetReducedWireframe);    
209                                                   
210    EtcSetFullWireframe = new QAction("Set full    
211    EtcSetFullWireframe->setFont(*font);           
212    connect(EtcSetFullWireframe, SIGNAL(trigger    
213            SLOT(EtcSetFullWireframeCB()));        
214    etcmenu->addAction(EtcSetFullWireframe);       
215                                                   
216    EtcVisibMInvisibD = new QAction("Visible mo    
217                                    this);         
218    EtcVisibMInvisibD->setFont(*font);             
219    connect(EtcVisibMInvisibD, SIGNAL(triggered    
220            SLOT(EtcVisibMInvisibDCB()));          
221    etcmenu->addAction(EtcVisibMInvisibD);         
222                                                   
223    EtcVisibMVisibD = new QAction("Visible moth    
224    EtcVisibMVisibD->setFont(*font);               
225    connect(EtcVisibMVisibD, SIGNAL(triggered()    
226            SLOT(EtcVisibMVisibDCB()));            
227    etcmenu->addAction(EtcVisibMVisibD);           
228                                                   
229    EtcUpdateScene = new QAction("Update scene"    
230    EtcUpdateScene->setFont(*font);                
231    connect(EtcUpdateScene, SIGNAL(triggered())    
232            SLOT(EtcUpdateSceneCB()));             
233    etcmenu->addAction(EtcUpdateScene);            
234                                                   
235    EtcSceneGraphStats = new QAction("Scene gra    
236    EtcSceneGraphStats->setFont(*font);            
237    connect(EtcSceneGraphStats, SIGNAL(triggere    
238            SLOT(EtcSceneGraphStatsCB()));         
239    etcmenu->addAction(EtcSceneGraphStats);        
240                                                   
241                                                   
242   // Have a GL2PS render action :                 
243   const SbViewportRegion& vpRegion = fViewer->    
244   fGL2PSAction = new SoGL2PSAction(vpRegion);     
245   fViewer->setGLRenderAction(fGL2PSAction);       
246                                                   
247   // Else :                                       
248                                                   
249   // FWJ DEBUG                                    
250   //  G4cout << "G4OpenInventorQtViewer: setti    
251   //     fSoSelection << G4endl;                  
252   //  G4cout << "G4OpenInventorQtViewer: getNu    
253   //     fSoSelection->getNumChildren() << G4e    
254                                                   
255   fViewer->setSceneGraph(fSoSelection);           
256   fViewer->setTransparencyType(SoGLRenderActio    
257   fViewer->viewAll();                             
258   fViewer->saveHomePosition();                    
259   // SOMEHOW this also the OIQt main window ti    
260   if (!uiQt) fViewer->setTitle(fName);            
261 #if QT_VERSION < 0x060000                         
262   fViewer->show();                                
263                                                   
264   // This SHOULD invoke the event loop:           
265   //  if(fShell) {                                
266                                                   
267   QWidget* mainWin = SoQt::getTopLevelWidget()    
268                                                   
269   // FWJ DEBUG                                    
270   //  G4cout << "G4OIQtViewer: calling SoQt::s    
271   //         << G4endl;                           
272                                                   
273   SoQt::show(mainWin);                            
274   fInteractorManager->FlushAndWaitExecution();    
275                                                   
276   //  }                                           
277   fInteractorManager->SetCreatedInteractor(fVi    
278 #else                                             
279   fViewer->setupSceneGraph();                     
280 #endif                                            
281 }                                                 
282                                                   
283                                                   
284 G4OpenInventorQtViewer::~G4OpenInventorQtViewe    
285 {                                                 
286   //  if(fShell) fInteractorManager->RemoveShe    
287   if(fViewer) {                                   
288     fViewer->setSceneGraph(0);                    
289     //FIXME : SGI : the below "delete" block t    
290 #if 0x060000 <= QT_VERSION                        
291     delete fViewer;                               
292 #endif                                            
293   }                                               
294 #if 0x060000 <= QT_VERSION                        
295   delete fDestroyCallback;                        
296 #endif                                            
297 }                                                 
298                                                   
299 void G4OpenInventorQtViewer::FinishView()         
300 {                                                 
301   if(!fViewer) return;                            
302   fViewer->viewAll();                             
303   fViewer->saveHomePosition();                    
304 }                                                 
305                                                   
306 void G4OpenInventorQtViewer::SetView()            
307 {                                                 
308   G4OpenInventorViewer::SetView();                
309   if(!fViewer) return;                            
310   // Background.                                  
311   G4Colour b = fVP.GetBackgroundColour();         
312   fViewer->setBackgroundColor                     
313     (SbColor((float)b.GetRed(),(float)b.GetGre    
314 }                                                 
315                                                   
316 void G4OpenInventorQtViewer::ViewerRender()       
317 {                                                 
318   if(!fViewer) return;                            
319   fViewer->render();                              
320 }                                                 
321                                                   
322 SoCamera* G4OpenInventorQtViewer::GetCamera ()    
323   if(!fViewer) return 0;                          
324   return fViewer->getCamera();                    
325 }                                                 
326                                                   
327                                                   
328 // User interaction finished: update VPs          
329 //void G4OpenInventorQtViewer::FinishCB(void*     
330 //{                                               
331 //   G4cout << "FINISHCB CALLED !!!!!" << G4en    
332 //}                                               
333                                                   
334                                                   
335 // File menu...                                   
336                                                   
337 void G4OpenInventorQtViewer::FileWritePSCB()      
338 {                                                 
339    //   G4cout << "G4OIQtViewer: File: Write P    
340    // FWJ Workaround: avoids empty 2nd page in    
341    SbBool superimpState =                         
342       fViewer->getSuperimpositionEnabled(fView    
343    fViewer->setSuperimpositionEnabled(fViewer-    
344    WritePostScript();                             
345    if (superimpState)                             
346       fViewer->setSuperimpositionEnabled(fView    
347 }                                                 
348                                                   
349 void G4OpenInventorQtViewer::FileWritePDFCB()     
350 {                                                 
351    //   G4cout << "G4OIQtViewer: File: Write P    
352    // FWJ Workaround: avoids empty 2nd page in    
353    SbBool superimpState =                         
354       fViewer->getSuperimpositionEnabled(fView    
355    fViewer->setSuperimpositionEnabled(fViewer-    
356    WritePDF();                                    
357    if (superimpState)                             
358       fViewer->setSuperimpositionEnabled(fView    
359 }                                                 
360                                                   
361 void G4OpenInventorQtViewer::FileWriteIVCB()      
362 {                                                 
363    //   G4cout << "G4OIQtViewer: File: Write I    
364    WriteInventor();                               
365 }                                                 
366                                                   
367 void G4OpenInventorQtViewer::FileEscapeCB()       
368 {                                                 
369    //   G4cout << "G4OIQtViewer: File: Escape     
370    static_cast<G4SoQt*>(fInteractorManager)->E    
371    //   Escape();                                 
372 }                                                 
373                                                   
374 // Etc menu...                                    
375                                                   
376 void                                              
377 G4OpenInventorQtViewer::EtcEraseDetectorCB()      
378 {                                                 
379    //   G4cout << "G4OIQtViewer: Etc: Erase De    
380    EraseDetector();                               
381 }                                                 
382                                                   
383 void                                              
384 G4OpenInventorQtViewer::EtcEraseEventCB()         
385 {                                                 
386    //   G4cout << "G4OIQtViewer: Etc: Erase Ev    
387    EraseEvent();                                  
388 }                                                 
389                                                   
390 void G4OpenInventorQtViewer::EtcSetSolidCB()      
391 {                                                 
392    //   G4cout << "G4OIQtViewer: Etc: Set Soli    
393    SetSolid();                                    
394 }                                                 
395                                                   
396 void G4OpenInventorQtViewer::EtcSetReducedWire    
397 {                                                 
398    // G4cout << "G4OIQtViewer: Etc: Set Reduce    
399    SetReducedWireFrame(true);                     
400 }                                                 
401                                                   
402 void G4OpenInventorQtViewer::EtcSetFullWirefra    
403 {                                                 
404    // G4cout << "G4OIQtViewer: Etc: Set Full W    
405    SetReducedWireFrame(false);                    
406 }                                                 
407                                                   
408 void G4OpenInventorQtViewer::EtcVisibMInvisibD    
409 {                                                 
410    // G4cout << "G4OIQtViewer: Etc: Visible Mo    
411    //   " CALLBACK" << G4endl;                    
412    SetPreview();                                  
413 }                                                 
414                                                   
415 void G4OpenInventorQtViewer::EtcVisibMVisibDCB    
416 {                                                 
417    // G4cout << "G4OIQtViewer: Etc: Visible Mo    
418    // "CALLBACK" << G4endl;                       
419    SetPreviewAndFull();                           
420 }                                                 
421                                                   
422 void G4OpenInventorQtViewer::EtcUpdateSceneCB(    
423 {                                                 
424    //   G4cout << "G4OIQtViewer: Etc: Update S    
425    UpdateScene();                                 
426 }                                                 
427                                                   
428 void G4OpenInventorQtViewer::EtcSceneGraphStat    
429 {                                                 
430    //   G4cout << "G4OIQtViewer: Etc: Scene Gr    
431    SceneGraphStatistics();                        
432 }                                                 
433