Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 // 28 // 29 // Laurent Garnier 27th October 2011 29 // Laurent Garnier 27th October 2011 30 30 >> 31 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER >> 32 31 #include "G4OpenGLStoredQtSceneHandler.hh" 33 #include "G4OpenGLStoredQtSceneHandler.hh" 32 34 33 #include "G4PhysicalVolumeModel.hh" 35 #include "G4PhysicalVolumeModel.hh" 34 #include "G4LogicalVolumeModel.hh" 36 #include "G4LogicalVolumeModel.hh" 35 #include "G4Text.hh" 37 #include "G4Text.hh" 36 #include "G4VPhysicalVolume.hh" 38 #include "G4VPhysicalVolume.hh" 37 #include "G4OpenGLQtViewer.hh" 39 #include "G4OpenGLQtViewer.hh" 38 #include <typeinfo> 40 #include <typeinfo> 39 #include <sstream> 41 #include <sstream> 40 42 41 G4OpenGLStoredQtSceneHandler::G4OpenGLStoredQt 43 G4OpenGLStoredQtSceneHandler::G4OpenGLStoredQtSceneHandler 42 (G4VGraphicsSystem& system, 44 (G4VGraphicsSystem& system, 43 const G4String& name): 45 const G4String& name): 44 G4OpenGLStoredSceneHandler (system, name) 46 G4OpenGLStoredSceneHandler (system, name) 45 {} 47 {} 46 48 47 G4OpenGLStoredQtSceneHandler::~G4OpenGLStoredQ 49 G4OpenGLStoredQtSceneHandler::~G4OpenGLStoredQtSceneHandler () 48 {} 50 {} 49 51 50 G4bool G4OpenGLStoredQtSceneHandler::ExtraPOPr 52 G4bool G4OpenGLStoredQtSceneHandler::ExtraPOProcessing 51 (const G4Visible& visible, size_t currentPOLis 53 (const G4Visible& visible, size_t currentPOListIndex) 52 { 54 { 53 G4bool usesGLCommands = true; 55 G4bool usesGLCommands = true; 54 56 55 try { 57 try { 56 const G4Text& g4Text = dynamic_cast<const 58 const G4Text& g4Text = dynamic_cast<const G4Text&>(visible); 57 G4TextPlus* pG4TextPlus = new G4TextPlus(g 59 G4TextPlus* pG4TextPlus = new G4TextPlus(g4Text); 58 pG4TextPlus->fProcessing2D = fProcessing2D 60 pG4TextPlus->fProcessing2D = fProcessing2D; 59 fPOList[currentPOListIndex].fpG4TextPlus = 61 fPOList[currentPOListIndex].fpG4TextPlus = pG4TextPlus; 60 usesGLCommands = false; 62 usesGLCommands = false; 61 } 63 } 62 catch (const std::bad_cast&) {} // No speci 64 catch (const std::bad_cast&) {} // No special action if not text. Just carry on. 63 65 64 G4PhysicalVolumeModel* pPVModel = 66 G4PhysicalVolumeModel* pPVModel = 65 dynamic_cast<G4PhysicalVolumeModel*>(fpMod 67 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 66 G4LogicalVolumeModel* pLVModel = 68 G4LogicalVolumeModel* pLVModel = 67 dynamic_cast<G4LogicalVolumeModel*>(pPVMod 69 dynamic_cast<G4LogicalVolumeModel*>(pPVModel); 68 if (pPVModel && !pLVModel) { 70 if (pPVModel && !pLVModel) { 69 71 70 // This call comes from a G4PhysicalVolume 72 // This call comes from a G4PhysicalVolumeModel. drawnPVPath is 71 // the path of the current drawn (non-cull 73 // the path of the current drawn (non-culled) volume in terms of 72 // drawn (non-culled) ancestors. Each nod << 74 // drawn (non-culled) ancesters. Each node is identified by a 73 // PVNodeID object, which is a physical vo 75 // PVNodeID object, which is a physical volume and copy number. It 74 // is a vector of PVNodeIDs corresponding 76 // is a vector of PVNodeIDs corresponding to the geometry hierarchy 75 // actually selected, i.e., not culled. 77 // actually selected, i.e., not culled. 76 // typedef G4PhysicalVolumeModel::G4Phy 78 // typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID; 77 // typedef std::vector<PVNodeID> PVPath 79 // typedef std::vector<PVNodeID> PVPath; 78 80 79 // The simplest algorithm, used by the Ope 81 // The simplest algorithm, used by the Open Inventor Driver 80 // developers, is to rely on the fact the 82 // developers, is to rely on the fact the G4PhysicalVolumeModel 81 // traverses the geometry hierarchy in an 83 // traverses the geometry hierarchy in an orderly manner. The last 82 // mother, if any, will be the node to whi 84 // mother, if any, will be the node to which the volume should be 83 // added. So it is enough to keep a map o 85 // added. So it is enough to keep a map of scene graph nodes keyed 84 // on the volume path ID. Actually, it is 86 // on the volume path ID. Actually, it is enough to use the logical 85 // volume as the key. (An alternative wou 87 // volume as the key. (An alternative would be to keep the PVNodeID 86 // in the tree and match the PVPath from t 88 // in the tree and match the PVPath from the root down.) 87 89 88 // BUT IN OPENGL, IF THERE ARE TRANSPARENT 90 // BUT IN OPENGL, IF THERE ARE TRANSPARENT OBJECTS, VOLUMES DO NOT 89 // ARRIVE IN THE ABOVE ORDER. (TRANSPAREN 91 // ARRIVE IN THE ABOVE ORDER. (TRANSPARENT OBJECTS ARE DRWAN 90 // LAST.) SO WE MUST BE MORE SOPHISTICATE 92 // LAST.) SO WE MUST BE MORE SOPHISTICATED IN CONSTRUCTING A 91 // TREE. 93 // TREE. 92 94 93 // build a path for tree viewer 95 // build a path for tree viewer 94 G4OpenGLQtViewer* pGLViewer = dynamic_cast 96 G4OpenGLQtViewer* pGLViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer); 95 if ( pGLViewer ) { 97 if ( pGLViewer ) { 96 pGLViewer->addPVSceneTreeElement(fpModel << 98 pGLViewer->addPVSceneTreeElement(fpModel->GetCurrentDescription(),pPVModel,currentPOListIndex); 97 } 99 } 98 100 99 } else { // Not from a G4PhysicalVolumeMode 101 } else { // Not from a G4PhysicalVolumeModel. 100 102 101 if (fpModel) { 103 if (fpModel) { 102 104 103 105 104 // build a path for tree viewer 106 // build a path for tree viewer 105 G4OpenGLQtViewer* pGLViewer = dynamic_ca 107 G4OpenGLQtViewer* pGLViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer); 106 if ( pGLViewer ) { 108 if ( pGLViewer ) { 107 pGLViewer->addNonPVSceneTreeElement(fp << 109 pGLViewer->addNonPVSceneTreeElement(fpModel->GetType(),currentPOListIndex,fpModel->GetCurrentDescription().data(),visible); 108 } 110 } 109 } 111 } 110 } 112 } 111 113 112 return usesGLCommands; 114 return usesGLCommands; 113 } 115 } 114 116 115 G4bool G4OpenGLStoredQtSceneHandler::ExtraTOPr 117 G4bool G4OpenGLStoredQtSceneHandler::ExtraTOProcessing 116 (const G4Visible& visible, size_t currentTOLis 118 (const G4Visible& visible, size_t currentTOListIndex) 117 { 119 { 118 120 119 G4bool usesGLCommands = true; 121 G4bool usesGLCommands = true; 120 122 121 try { 123 try { 122 const G4Text& g4Text = dynamic_cast<const 124 const G4Text& g4Text = dynamic_cast<const G4Text&>(visible); 123 G4TextPlus* pG4TextPlus = new G4TextPlus(g 125 G4TextPlus* pG4TextPlus = new G4TextPlus(g4Text); 124 pG4TextPlus->fProcessing2D = fProcessing2D 126 pG4TextPlus->fProcessing2D = fProcessing2D; 125 fTOList[currentTOListIndex].fpG4TextPlus = 127 fTOList[currentTOListIndex].fpG4TextPlus = pG4TextPlus; 126 usesGLCommands = false; 128 usesGLCommands = false; 127 } 129 } 128 catch (const std::bad_cast&) {} // Do nothi 130 catch (const std::bad_cast&) {} // Do nothing if not text. 129 131 130 return usesGLCommands; 132 return usesGLCommands; 131 } 133 } 132 134 133 void G4OpenGLStoredQtSceneHandler::ClearStore 135 void G4OpenGLStoredQtSceneHandler::ClearStore () { 134 136 135 //G4cout << "G4OpenGLStoredQtSceneHandler::C 137 //G4cout << "G4OpenGLStoredQtSceneHandler::ClearStore" << G4endl; 136 138 137 G4OpenGLStoredSceneHandler::ClearStore (); << 139 G4OpenGLStoredSceneHandler::ClearStore (); // Sets need kernel visit, etc. 138 << 140 // Should recreate the tree 139 // Not needed - the old scene tree is curren << 141 G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer); 140 // this code somehow affects the view in rar << 142 if ( pGLQtViewer ) { 141 // the volume does not return to its origina << 143 pGLQtViewer->clearTreeWidget(); 142 // this, pending a review of the old scene t << 144 } 143 // // Should recreate the tree << 144 // G4OpenGLQtViewer* pGLQtViewer = dynamic_ca << 145 // if ( pGLQtViewer ) { << 146 // pGLQtViewer->clearTreeWidget(); << 147 // } << 148 } 145 } 149 146 150 void G4OpenGLStoredQtSceneHandler::ClearTransi 147 void G4OpenGLStoredQtSceneHandler::ClearTransientStore () { 151 148 152 //G4cout << "G4OpenGLStoredQtSceneHandler::C 149 //G4cout << "G4OpenGLStoredQtSceneHandler::ClearTransientStore" << G4endl; 153 150 154 G4OpenGLStoredSceneHandler::ClearTransientSt 151 G4OpenGLStoredSceneHandler::ClearTransientStore (); 155 152 156 // Should recreate the tree 153 // Should recreate the tree 157 // Make sure screen corresponds to graphical 154 // Make sure screen corresponds to graphical database... 158 // FIXME : L.Garnier April 2012 : Could caus 155 // FIXME : L.Garnier April 2012 : Could cause a infinite loop ? 159 if (fpViewer) { 156 if (fpViewer) { 160 fpViewer -> SetView (); 157 fpViewer -> SetView (); 161 fpViewer -> ClearView (); 158 fpViewer -> ClearView (); 162 fpViewer -> DrawView (); 159 fpViewer -> DrawView (); 163 } 160 } 164 } 161 } 165 162 166 void G4OpenGLStoredQtSceneHandler::SetScene(G4 163 void G4OpenGLStoredQtSceneHandler::SetScene(G4Scene* pScene){ 167 164 168 if (pScene != fpScene) { 165 if (pScene != fpScene) { 169 G4OpenGLQtViewer* pGLQtViewer = dynamic_ca 166 G4OpenGLQtViewer* pGLQtViewer = dynamic_cast<G4OpenGLQtViewer*>(fpViewer); 170 if ( pGLQtViewer ) { 167 if ( pGLQtViewer ) { 171 pGLQtViewer->clearTreeWidget(); 168 pGLQtViewer->clearTreeWidget(); 172 } 169 } 173 } 170 } 174 G4VSceneHandler::SetScene(pScene); 171 G4VSceneHandler::SetScene(pScene); 175 } 172 } >> 173 >> 174 #endif 176 175