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