Geant4  10.02
SoDetectorTreeKit.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 // $Id: SoDetectorTreeKit.cc 66373 2012-12-18 09:41:34Z gcosmo $
29 //
30 /*-----------------------------HEPVis----------------------------------------*/
31 /* */
32 /* Node: SoDetectorTreeKit */
33 /* Description: Represents a single sided silicon strip detector */
34 /* Author: Joe Boudreau Nov 11 1996 */
35 /* */
36 /*---------------------------------------------------------------------------*/
37 
38 #ifdef G4VIS_BUILD_OI_DRIVER
39 
40 // this :
41 #include "HEPVis/nodekits/SoDetectorTreeKit.h"
42 
43 #include <Inventor/SoPickedPoint.h>
44 #include <Inventor/nodes/SoSeparator.h>
45 #include <Inventor/nodes/SoPickStyle.h>
46 #include <Inventor/nodes/SoDrawStyle.h>
47 #include <Inventor/nodes/SoSwitch.h>
48 #include <Inventor/nodes/SoMaterial.h>
49 #include <Inventor/nodes/SoUnits.h>
50 #include <Inventor/nodes/SoTransform.h>
51 #include <Inventor/nodes/SoEventCallback.h>
52 #include <Inventor/nodekits/SoSeparatorKit.h>
53 #include <Inventor/nodekits/SoShapeKit.h>
54 #include <Inventor/nodekits/SoAppearanceKit.h>
55 #include <Inventor/nodekits/SoNodeKitListPart.h>
56 #include <Inventor/nodekits/SoBaseKit.h>
57 #include <Inventor/nodes/SoTexture2Transform.h>
58 #include <Inventor/events/SoMouseButtonEvent.h>
59 #include <Inventor/actions/SoHandleEventAction.h>
60 
61 #include <HEPVis/actions/SoAlternateRepAction.h>
62 
63 #include <cmath>
64 
65 // This statement is required
66 SO_KIT_SOURCE(SoDetectorTreeKit)
67 
68 // initClass
69 void SoDetectorTreeKit::initClass(){
70  SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBaseKit,"BaseKit");
71 }
72 
73 // Constructor
74 SoDetectorTreeKit::SoDetectorTreeKit() {
75  SO_KIT_CONSTRUCTOR(SoDetectorTreeKit);
76 
77  SO_NODE_ADD_FIELD(alternateRep, (NULL));
78 
79  SO_KIT_ADD_CATALOG_ENTRY ( topSeparator, SoSeparator, FALSE, this,\0, FALSE);
80  SO_KIT_ADD_CATALOG_ENTRY ( pickStyle, SoSeparator, TRUE , topSeparator,\0, TRUE);
81  SO_KIT_ADD_CATALOG_ENTRY ( appearance, SoAppearanceKit, TRUE, topSeparator ,\0, TRUE);
82  SO_KIT_ADD_CATALOG_ENTRY ( units, SoUnits, TRUE, topSeparator ,\0, TRUE);
83  SO_KIT_ADD_CATALOG_ENTRY ( transform, SoTransform, TRUE , topSeparator,\0, TRUE);
84  SO_KIT_ADD_CATALOG_ENTRY (texture2Transform, SoTexture2Transform, TRUE, topSeparator ,\0, TRUE);
85  SO_KIT_ADD_CATALOG_ENTRY ( childList, SoSwitch, FALSE, topSeparator,\0, FALSE);
86  SO_KIT_ADD_CATALOG_ENTRY ( previewSeparator, SoSeparator, FALSE, childList,\0, TRUE);
87  SO_KIT_ADD_CATALOG_ENTRY ( fullSeparator, SoSeparator, FALSE, childList,\0, TRUE);
88 
89  SO_KIT_INIT_INSTANCE();
90  createInitialTree();
91 }
92 
93 // Destructor
94 SoDetectorTreeKit::~SoDetectorTreeKit() {
95 }
96 
97 
98 SbBool SoDetectorTreeKit::affectsState() const {
99  return FALSE;
100 }
101 
102 void SoDetectorTreeKit::createInitialTree() {
103 
104  SoEventCallback *myCallback = new SoEventCallback();
105  myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
106  SoDetectorTreeKit::expand,
107  this);
108  myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
109  SoDetectorTreeKit::contract ,
110  this);
111  if(setPart("callbackList[0]",myCallback)==FALSE) myCallback->unref();
112 
113  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
114  theChildList->whichChild.setValue(0);
115 }
116 
117 void SoDetectorTreeKit::expand(void *userData, SoEventCallback *eventCB){
118 
119  // Was the event previously handled? Is it the right kind?
120 
121  if (eventCB->isHandled()) return;
122  const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
123  if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
124  if (!event->wasCtrlDown()) return;
125  if (event->wasShiftDown()) return;
126 
127  // Which Detector is this being called for?
128  SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
129 
130  // Find out whether that's the one that has been picked.
131  // "This' is the lowest detector tree kit in the hierarchy.
132  SoHandleEventAction *handleEventAction = eventCB->getAction();
133  const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
134  if (!pickedPoint) return;
135 
136  SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
137  SoNode *ancestorNode=NULL;
138  for (int i=0;i<path->getLength();i++) {
139  ancestorNode = path->getNodeFromTail(i);
140  if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) break;
141  }
142  if (This!=ancestorNode) return;
143  // if (!ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) return;
144 
145  // Deactivate the Preview
146  This->setPreview(FALSE);
147  eventCB->setHandled();
148 
149 }
150 
151 void SoDetectorTreeKit::contract(void *userData, SoEventCallback *eventCB){
152 
153  // Was the event previously handled? Is it the right kind?
154  if (eventCB->isHandled()) return;
155  const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
156  if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
157  if (event->wasCtrlDown()) return;
158  if (!event->wasShiftDown()) return;
159 
160  // Which Detector is this being called for?
161  SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
162 
163  // Find out whether that's the one that has been picked
164  SoHandleEventAction *handleEventAction = eventCB->getAction();
165  const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
166  if (!pickedPoint) return;
167 
168  // Find out whether that's the one that has been picked.
169  // "This" is the lowest detector tree kit in the hierarchy.
170  SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
171  SoNode *ancestorNode=NULL;
172  SbBool firstTreeFound=FALSE;
173  for (int i=0;i<path->getLength();i++) {
174  ancestorNode = path->getNodeFromTail(i);
175  if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) {
176  if (!firstTreeFound) {
177  if (This!=ancestorNode) return;
178  firstTreeFound=TRUE;
179  }
180  SoDetectorTreeKit *That = (SoDetectorTreeKit *) ancestorNode;
181  if (!That->getPreview()) {
182  That->setPreview(TRUE);
183  eventCB->setHandled();
184  return;
185  }
186  }
187  }
188 }
189 
190 void SoDetectorTreeKit::setPreview(SbBool Flag) {
191  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
192  if (Flag) {
193  theChildList->whichChild.setValue(0);
194  }
195  else {
196  theChildList->whichChild.setValue(1);
197  }
198 }
199 
200 SbBool SoDetectorTreeKit::getPreview() const {
201  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
202  if (theChildList->whichChild.getValue()==0) return TRUE;
203  return FALSE;
204 }
205 
206 
207 void SoDetectorTreeKit::setPreviewAndFull() {
208  SoSwitch *theChildList = (SoSwitch *) childList.getValue();
209  theChildList->whichChild.setValue(SO_SWITCH_ALL);
210 }
211 
212 SoSeparator *SoDetectorTreeKit::getPreviewSeparator() const {
213  return (SoSeparator *) previewSeparator.getValue();
214 }
215 
216 SoSeparator *SoDetectorTreeKit::getFullSeparator() const {
217  return (SoSeparator *) fullSeparator.getValue();
218 }
219 
220 
221 
222 
223 // generateAlternateRep
224 void SoDetectorTreeKit::generateAlternateRep() {
225  alternateRep.setValue(topSeparator.getValue());
226 }
227 
228 void SoDetectorTreeKit::clearAlternateRep() {
229  alternateRep.setValue(NULL);
230 }
232 void SoDetectorTreeKit::doAction(
233  SoAction* aAction
234 )
237 {
238  SO_ALTERNATEREP_DO_ACTION(aAction)
239  SoBaseKit::doAction(aAction);
240 }
241 
242 #endif
#define userData
Definition: xmlparse.cc:572
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55