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 /*-----------------------------HEPVis--------- 29 /*-----------------------------HEPVis----------------------------------------*/ 30 /* 30 /* */ 31 /* Node: SoDetectorTreeKit 31 /* Node: SoDetectorTreeKit */ 32 /* Description: Represents a single sided 32 /* Description: Represents a single sided silicon strip detector */ 33 /* Author: Joe Boudreau Nov 11 1996 33 /* Author: Joe Boudreau Nov 11 1996 */ 34 /* 34 /* */ 35 /*-------------------------------------------- 35 /*---------------------------------------------------------------------------*/ 36 36 >> 37 #ifdef G4VIS_BUILD_OI_DRIVER >> 38 37 // this : 39 // this : 38 #include "HEPVis/nodekits/SoDetectorTreeKit.h" 40 #include "HEPVis/nodekits/SoDetectorTreeKit.h" 39 41 40 #include <Inventor/SoPickedPoint.h> 42 #include <Inventor/SoPickedPoint.h> 41 #include <Inventor/nodes/SoSeparator.h> 43 #include <Inventor/nodes/SoSeparator.h> 42 #include <Inventor/nodes/SoPickStyle.h> 44 #include <Inventor/nodes/SoPickStyle.h> 43 #include <Inventor/nodes/SoDrawStyle.h> 45 #include <Inventor/nodes/SoDrawStyle.h> 44 #include <Inventor/nodes/SoSwitch.h> 46 #include <Inventor/nodes/SoSwitch.h> 45 #include <Inventor/nodes/SoMaterial.h> 47 #include <Inventor/nodes/SoMaterial.h> 46 #include <Inventor/nodes/SoUnits.h> 48 #include <Inventor/nodes/SoUnits.h> 47 #include <Inventor/nodes/SoTransform.h> 49 #include <Inventor/nodes/SoTransform.h> 48 #include <Inventor/nodes/SoEventCallback.h> 50 #include <Inventor/nodes/SoEventCallback.h> 49 #include <Inventor/nodekits/SoSeparatorKit.h> 51 #include <Inventor/nodekits/SoSeparatorKit.h> 50 #include <Inventor/nodekits/SoShapeKit.h> 52 #include <Inventor/nodekits/SoShapeKit.h> 51 #include <Inventor/nodekits/SoAppearanceKit.h> 53 #include <Inventor/nodekits/SoAppearanceKit.h> 52 #include <Inventor/nodekits/SoNodeKitListPart. 54 #include <Inventor/nodekits/SoNodeKitListPart.h> 53 #include <Inventor/nodekits/SoBaseKit.h> 55 #include <Inventor/nodekits/SoBaseKit.h> 54 #include <Inventor/nodes/SoTexture2Transform.h 56 #include <Inventor/nodes/SoTexture2Transform.h> 55 #include <Inventor/events/SoMouseButtonEvent.h 57 #include <Inventor/events/SoMouseButtonEvent.h> 56 #include <Inventor/actions/SoHandleEventAction 58 #include <Inventor/actions/SoHandleEventAction.h> 57 59 58 #include <HEPVis/actions/SoAlternateRepAction. 60 #include <HEPVis/actions/SoAlternateRepAction.h> 59 61 60 #include <cmath> 62 #include <cmath> 61 63 62 // This statement is required 64 // This statement is required 63 SO_KIT_SOURCE(SoDetectorTreeKit) 65 SO_KIT_SOURCE(SoDetectorTreeKit) 64 66 65 // initClass 67 // initClass 66 void SoDetectorTreeKit::initClass(){ 68 void SoDetectorTreeKit::initClass(){ 67 static bool first = true; 69 static bool first = true; 68 if (first) { 70 if (first) { 69 first = false; 71 first = false; 70 SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBase 72 SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBaseKit,"BaseKit"); 71 } 73 } 72 } 74 } 73 75 74 // Constructor 76 // Constructor 75 SoDetectorTreeKit::SoDetectorTreeKit() { 77 SoDetectorTreeKit::SoDetectorTreeKit() { 76 SO_KIT_CONSTRUCTOR(SoDetectorTreeKit); 78 SO_KIT_CONSTRUCTOR(SoDetectorTreeKit); 77 79 78 SO_NODE_ADD_FIELD(alternateRep, (NULL)); 80 SO_NODE_ADD_FIELD(alternateRep, (NULL)); 79 81 80 SO_KIT_ADD_CATALOG_ENTRY ( topSepara 82 SO_KIT_ADD_CATALOG_ENTRY ( topSeparator, SoSeparator, FALSE, this,\0, FALSE); 81 SO_KIT_ADD_CATALOG_ENTRY ( pickSt 83 SO_KIT_ADD_CATALOG_ENTRY ( pickStyle, SoSeparator, TRUE , topSeparator,\0, TRUE); 82 SO_KIT_ADD_CATALOG_ENTRY ( appeara 84 SO_KIT_ADD_CATALOG_ENTRY ( appearance, SoAppearanceKit, TRUE, topSeparator ,\0, TRUE); 83 SO_KIT_ADD_CATALOG_ENTRY ( un 85 SO_KIT_ADD_CATALOG_ENTRY ( units, SoUnits, TRUE, topSeparator ,\0, TRUE); 84 SO_KIT_ADD_CATALOG_ENTRY ( transf 86 SO_KIT_ADD_CATALOG_ENTRY ( transform, SoTransform, TRUE , topSeparator,\0, TRUE); 85 SO_KIT_ADD_CATALOG_ENTRY (texture2Transf 87 SO_KIT_ADD_CATALOG_ENTRY (texture2Transform, SoTexture2Transform, TRUE, topSeparator ,\0, TRUE); 86 SO_KIT_ADD_CATALOG_ENTRY ( childL 88 SO_KIT_ADD_CATALOG_ENTRY ( childList, SoSwitch, FALSE, topSeparator,\0, FALSE); 87 SO_KIT_ADD_CATALOG_ENTRY ( previewSepara 89 SO_KIT_ADD_CATALOG_ENTRY ( previewSeparator, SoSeparator, FALSE, childList,\0, TRUE); 88 SO_KIT_ADD_CATALOG_ENTRY ( fullSepara 90 SO_KIT_ADD_CATALOG_ENTRY ( fullSeparator, SoSeparator, FALSE, childList,\0, TRUE); 89 91 90 SO_KIT_INIT_INSTANCE(); 92 SO_KIT_INIT_INSTANCE(); 91 createInitialTree(); 93 createInitialTree(); 92 } 94 } 93 95 94 // Destructor 96 // Destructor 95 SoDetectorTreeKit::~SoDetectorTreeKit() { 97 SoDetectorTreeKit::~SoDetectorTreeKit() { 96 } 98 } 97 99 98 100 99 SbBool SoDetectorTreeKit::affectsState() const 101 SbBool SoDetectorTreeKit::affectsState() const { 100 return FALSE; 102 return FALSE; 101 } 103 } 102 104 103 void SoDetectorTreeKit::createInitialTree() { 105 void SoDetectorTreeKit::createInitialTree() { 104 106 105 SoEventCallback *myCallback = new SoEventCal 107 SoEventCallback *myCallback = new SoEventCallback(); 106 myCallback->addEventCallback(SoMouseButtonEv 108 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(), 107 SoDetectorTreeK 109 SoDetectorTreeKit::expand, 108 this); 110 this); 109 myCallback->addEventCallback(SoMouseButtonEv 111 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(), 110 SoDetectorTreeK 112 SoDetectorTreeKit::contract , 111 this); 113 this); 112 if(setPart("callbackList[0]",myCallback)==FA 114 if(setPart("callbackList[0]",myCallback)==FALSE) myCallback->unref(); 113 115 114 SoSwitch *theChildList = (SoSwitch *) childL 116 SoSwitch *theChildList = (SoSwitch *) childList.getValue(); 115 theChildList->whichChild.setValue(0); 117 theChildList->whichChild.setValue(0); 116 } 118 } 117 119 118 void SoDetectorTreeKit::expand(void *userData, 120 void SoDetectorTreeKit::expand(void *userData, SoEventCallback *eventCB){ 119 121 120 // Was the event previously handled? Is it t 122 // Was the event previously handled? Is it the right kind? 121 123 122 if (eventCB->isHandled()) return; 124 if (eventCB->isHandled()) return; 123 const SoMouseButtonEvent *event= (SoMouseBut 125 const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent(); 124 if (!SoMouseButtonEvent::isButtonPressEvent( 126 if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return; 125 if (!event->wasCtrlDown()) return; 127 if (!event->wasCtrlDown()) return; 126 if (event->wasShiftDown()) return; 128 if (event->wasShiftDown()) return; 127 129 128 // Which Detector is this being called for? 130 // Which Detector is this being called for? 129 SoDetectorTreeKit* This = (SoDetectorTreeKit 131 SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData; 130 132 131 // Find out whether that's the one that has 133 // Find out whether that's the one that has been picked. 132 // "This' is the lowest detector tree kit in 134 // "This' is the lowest detector tree kit in the hierarchy. 133 SoHandleEventAction *handleEventAction = eve 135 SoHandleEventAction *handleEventAction = eventCB->getAction(); 134 const SoPickedPoint *pickedPoint = handleEve 136 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint(); 135 if (!pickedPoint) return; 137 if (!pickedPoint) return; 136 138 137 SoFullPath* path = (SoFullPath*)pickedPoint- 139 SoFullPath* path = (SoFullPath*)pickedPoint->getPath(); 138 SoNode *ancestorNode=NULL; 140 SoNode *ancestorNode=NULL; 139 for (int i=0;i<path->getLength();i++) { 141 for (int i=0;i<path->getLength();i++) { 140 ancestorNode = path->getNodeFromTail(i); 142 ancestorNode = path->getNodeFromTail(i); 141 if (ancestorNode->isOfType(SoDetectorTreeK 143 if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) break; 142 } 144 } 143 if (This!=ancestorNode) return; 145 if (This!=ancestorNode) return; 144 // if (!ancestorNode->isOfType(SoDetectorTr 146 // if (!ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) return; 145 147 146 // Deactivate the Preview 148 // Deactivate the Preview 147 This->setPreview(FALSE); 149 This->setPreview(FALSE); 148 eventCB->setHandled(); 150 eventCB->setHandled(); 149 151 150 } 152 } 151 153 152 void SoDetectorTreeKit::contract(void *userDat 154 void SoDetectorTreeKit::contract(void *userData, SoEventCallback *eventCB){ 153 155 154 // Was the event previously handled? Is it t 156 // Was the event previously handled? Is it the right kind? 155 if (eventCB->isHandled()) return; 157 if (eventCB->isHandled()) return; 156 const SoMouseButtonEvent *event= (SoMouseBut 158 const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent(); 157 if (!SoMouseButtonEvent::isButtonPressEvent( 159 if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return; 158 if (event->wasCtrlDown()) return; 160 if (event->wasCtrlDown()) return; 159 if (!event->wasShiftDown()) return; 161 if (!event->wasShiftDown()) return; 160 162 161 // Which Detector is this being called for? 163 // Which Detector is this being called for? 162 SoDetectorTreeKit* This = (SoDetectorTreeKit 164 SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData; 163 165 164 // Find out whether that's the one that has 166 // Find out whether that's the one that has been picked 165 SoHandleEventAction *handleEventAction = eve 167 SoHandleEventAction *handleEventAction = eventCB->getAction(); 166 const SoPickedPoint *pickedPoint = handleEve 168 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint(); 167 if (!pickedPoint) return; 169 if (!pickedPoint) return; 168 170 169 // Find out whether that's the one that has 171 // Find out whether that's the one that has been picked. 170 // "This" is the lowest detector tree kit in 172 // "This" is the lowest detector tree kit in the hierarchy. 171 SoFullPath* path = (SoFullPath*)pickedPoint- 173 SoFullPath* path = (SoFullPath*)pickedPoint->getPath(); 172 SoNode *ancestorNode=NULL; 174 SoNode *ancestorNode=NULL; 173 SbBool firstTreeFound=FALSE; 175 SbBool firstTreeFound=FALSE; 174 for (int i=0;i<path->getLength();i++) { 176 for (int i=0;i<path->getLength();i++) { 175 ancestorNode = path->getNodeFromTail(i); 177 ancestorNode = path->getNodeFromTail(i); 176 if (ancestorNode->isOfType(SoDetectorTreeK 178 if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) { 177 if (!firstTreeFound) { 179 if (!firstTreeFound) { 178 if (This!=ancestorNode) return; 180 if (This!=ancestorNode) return; 179 firstTreeFound=TRUE; 181 firstTreeFound=TRUE; 180 } 182 } 181 SoDetectorTreeKit *That = (SoDetectorTre 183 SoDetectorTreeKit *That = (SoDetectorTreeKit *) ancestorNode; 182 if (!That->getPreview()) { 184 if (!That->getPreview()) { 183 That->setPreview(TRUE); 185 That->setPreview(TRUE); 184 eventCB->setHandled(); 186 eventCB->setHandled(); 185 return; 187 return; 186 } 188 } 187 } 189 } 188 } 190 } 189 } 191 } 190 192 191 void SoDetectorTreeKit::setPreview(SbBool Flag 193 void SoDetectorTreeKit::setPreview(SbBool Flag) { 192 SoSwitch *theChildList = (SoSwitch *) childL 194 SoSwitch *theChildList = (SoSwitch *) childList.getValue(); 193 if (Flag) { 195 if (Flag) { 194 theChildList->whichChild.setValue(0); 196 theChildList->whichChild.setValue(0); 195 } 197 } 196 else { 198 else { 197 theChildList->whichChild.setValue(1); 199 theChildList->whichChild.setValue(1); 198 } 200 } 199 } 201 } 200 202 201 SbBool SoDetectorTreeKit::getPreview() const { 203 SbBool SoDetectorTreeKit::getPreview() const { 202 SoSwitch *theChildList = (SoSwitch *) childL 204 SoSwitch *theChildList = (SoSwitch *) childList.getValue(); 203 if (theChildList->whichChild.getValue()==0) 205 if (theChildList->whichChild.getValue()==0) return TRUE; 204 return FALSE; 206 return FALSE; 205 } 207 } 206 208 207 209 208 void SoDetectorTreeKit::setPreviewAndFull() { 210 void SoDetectorTreeKit::setPreviewAndFull() { 209 SoSwitch *theChildList = (SoSwitch *) childL 211 SoSwitch *theChildList = (SoSwitch *) childList.getValue(); 210 theChildList->whichChild.setValue(SO_SWITCH_ 212 theChildList->whichChild.setValue(SO_SWITCH_ALL); 211 } 213 } 212 214 213 SoSeparator *SoDetectorTreeKit::getPreviewSepa 215 SoSeparator *SoDetectorTreeKit::getPreviewSeparator() const { 214 return (SoSeparator *) previewSeparator.getV 216 return (SoSeparator *) previewSeparator.getValue(); 215 } 217 } 216 218 217 SoSeparator *SoDetectorTreeKit::getFullSeparat 219 SoSeparator *SoDetectorTreeKit::getFullSeparator() const { 218 return (SoSeparator *) fullSeparator.getValu 220 return (SoSeparator *) fullSeparator.getValue(); 219 } 221 } 220 222 221 223 222 224 223 225 224 // generateAlternateRep 226 // generateAlternateRep 225 void SoDetectorTreeKit::generateAlternateRep() 227 void SoDetectorTreeKit::generateAlternateRep() { 226 alternateRep.setValue(topSeparator.getValue( 228 alternateRep.setValue(topSeparator.getValue()); 227 } 229 } 228 230 229 void SoDetectorTreeKit::clearAlternateRep() { 231 void SoDetectorTreeKit::clearAlternateRep() { 230 alternateRep.setValue(NULL); 232 alternateRep.setValue(NULL); 231 } 233 } 232 ////////////////////////////////////////////// 234 ////////////////////////////////////////////////////////////////////////////// 233 void SoDetectorTreeKit::doAction( 235 void SoDetectorTreeKit::doAction( 234 SoAction* aAction 236 SoAction* aAction 235 ) 237 ) 236 ////////////////////////////////////////////// 238 ////////////////////////////////////////////////////////////////////////////// 237 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 239 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 238 { 240 { 239 SO_ALTERNATEREP_DO_ACTION(aAction) 241 SO_ALTERNATEREP_DO_ACTION(aAction) 240 SoBaseKit::doAction(aAction); 242 SoBaseKit::doAction(aAction); 241 } 243 } >> 244 >> 245 #endif 242 246