G4OpenGLStoredQtSceneHandler.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4OpenGLStoredSceneHandler.cc,v 1.46 2010-11-10 17:11:20 allison Exp $
00028 // GEANT4 tag $Name: not supported by cvs2svn $
00029 //
00030 // 
00031 // Laurent Garnier  27th October 2011
00032 
00033 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
00034 
00035 #include "G4OpenGLStoredQtSceneHandler.hh"
00036 
00037 #include "G4PhysicalVolumeModel.hh"
00038 #include "G4LogicalVolumeModel.hh"
00039 #include "G4Text.hh"
00040 #include "G4VPhysicalVolume.hh"
00041 #include "G4OpenGLQtViewer.hh"
00042 #include <typeinfo>
00043 #include <sstream>
00044 
00045 G4OpenGLStoredQtSceneHandler::G4OpenGLStoredQtSceneHandler
00046 (G4VGraphicsSystem& system,
00047  const G4String& name):
00048 G4OpenGLStoredSceneHandler (system, name)
00049 {}
00050 
00051 G4OpenGLStoredQtSceneHandler::~G4OpenGLStoredQtSceneHandler ()
00052 {}
00053 
00054 G4bool G4OpenGLStoredQtSceneHandler::ExtraPOProcessing
00055 (const G4Visible& visible, size_t currentPOListIndex)
00056 {
00057   G4bool usesGLCommands = true;
00058 
00059   try {
00060     const G4Text& g4Text = dynamic_cast<const G4Text&>(visible);
00061     G4TextPlus* pG4TextPlus = new G4TextPlus(g4Text);
00062     pG4TextPlus->fProcessing2D = fProcessing2D;
00063     fPOList[currentPOListIndex].fpG4TextPlus = pG4TextPlus;
00064     usesGLCommands = false;
00065   }
00066   catch (std::bad_cast) {}  // No special action if not text.  Just carry on.
00067 
00068   G4PhysicalVolumeModel* pPVModel =
00069     dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00070   G4LogicalVolumeModel* pLVModel =
00071     dynamic_cast<G4LogicalVolumeModel*>(pPVModel);
00072   if (pPVModel && !pLVModel) {
00073 
00074     // This call comes from a G4PhysicalVolumeModel.  drawnPVPath is
00075     // the path of the current drawn (non-culled) volume in terms of
00076     // drawn (non-culled) ancesters.  Each node is identified by a
00077     // PVNodeID object, which is a physical volume and copy number.  It
00078     // is a vector of PVNodeIDs corresponding to the geometry hierarchy
00079     // actually selected, i.e., not culled.
00080     typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
00081     typedef std::vector<PVNodeID> PVPath;
00082 
00083     // The simplest algorithm, used by the Open Inventor Driver
00084     // developers, is to rely on the fact the G4PhysicalVolumeModel
00085     // traverses the geometry hierarchy in an orderly manner.  The last
00086     // mother, if any, will be the node to which the volume should be
00087     // added.  So it is enough to keep a map of scene graph nodes keyed
00088     // on the volume path ID.  Actually, it is enough to use the logical
00089     // volume as the key.  (An alternative would be to keep the PVNodeID
00090     // in the tree and match the PVPath from the root down.)
00091 
00092     // BUT IN OPENGL, IF THERE ARE TRANSPARENT OBJECTS, VOLUMES DO NOT
00093     // ARRIVE IN THE ABOVE ORDER.  (TRANSPARENT OBJECTS ARE DRWAN
00094     // LAST.)  SO WE MUST BE MORE SOPHISTICATED IN CONSTRUCTING A
00095     // TREE.
00096 
00097     // build a path for tree viewer
00098     G4OpenGLQtViewer* pGLViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
00099     if ( pGLViewer ) {
00100       pGLViewer->addPVSceneTreeElement(fpModel->GetCurrentDescription(),pPVModel,currentPOListIndex);
00101     }
00102 
00103   } else {  // Not from a G4PhysicalVolumeModel.
00104 
00105     if (fpModel) {
00106 
00107       
00108       // build a path for tree viewer
00109       G4OpenGLQtViewer* pGLViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
00110       if ( pGLViewer ) {
00111         pGLViewer->addNonPVSceneTreeElement(fpModel->GetType(),currentPOListIndex,fpModel->GetCurrentDescription().data(),visible);
00112       }
00113     }
00114   }
00115 
00116   return usesGLCommands;
00117 }
00118 
00119 G4bool G4OpenGLStoredQtSceneHandler::ExtraTOProcessing
00120 (const G4Visible& visible, size_t currentTOListIndex)
00121 {
00122 
00123   G4bool usesGLCommands = true;
00124 
00125   try {
00126     const G4Text& g4Text = dynamic_cast<const G4Text&>(visible);
00127     G4TextPlus* pG4TextPlus = new G4TextPlus(g4Text);
00128     pG4TextPlus->fProcessing2D = fProcessing2D;
00129     fTOList[currentTOListIndex].fpG4TextPlus = pG4TextPlus;
00130     usesGLCommands = false;
00131   }
00132   catch (std::bad_cast) {}  // Do nothing if not text.
00133 
00134   return usesGLCommands;
00135 }
00136 
00137 void G4OpenGLStoredQtSceneHandler::ClearStore () {
00138 
00139   //G4cout << "G4OpenGLStoredQtSceneHandler::ClearStore" << G4endl;
00140 
00141   G4OpenGLStoredSceneHandler::ClearStore ();  // Sets need kernel visit, etc.
00142   // Should recreate the tree
00143   G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
00144   if ( pGLQtViewer ) {
00145 #ifdef G4DEBUG_VIS_OGL
00146     printf("G4OpenGLStoredQtSceneHandler::ClearStore_________________________________\n" );
00147 #endif
00148     pGLQtViewer->clearTreeWidget();
00149   }
00150 }
00151 
00152 void G4OpenGLStoredQtSceneHandler::ClearTransientStore () {
00153 
00154   //G4cout << "G4OpenGLStoredQtSceneHandler::ClearTransientStore" << G4endl;
00155 
00156   G4OpenGLStoredSceneHandler::ClearTransientStore ();
00157 
00158   // Should recreate the tree
00159   G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
00160   if ( pGLQtViewer ) {
00161 #ifdef G4DEBUG_VIS_OGL
00162     printf("G4OpenGLStoredQtSceneHandler::ClearTransient_________________________________\n" );
00163 #endif
00164     //    pGLQtViewer->clearTreeWidget();
00165   }
00166   // Make sure screen corresponds to graphical database...
00167   // FIXME : L.Garnier April 2012 : Could cause a infinite loop ?
00168   if (fpViewer) {
00169     fpViewer -> SetView ();
00170     fpViewer -> ClearView ();
00171     fpViewer -> DrawView ();
00172   }
00173 }
00174 
00175 void G4OpenGLStoredQtSceneHandler::SetScene(G4Scene* pScene){
00176 
00177   if (pScene != fpScene) {
00178     G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer);
00179     if ( pGLQtViewer ) {
00180       pGLQtViewer->clearTreeWidget();
00181     }
00182   }
00183   G4VSceneHandler::SetScene(pScene);
00184 }
00185 
00186 #endif

Generated on Mon May 27 17:49:10 2013 for Geant4 by  doxygen 1.4.7