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