Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
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
65SO_KIT_SOURCE(SoDetectorTreeKit)
66
67// initClass
69 static bool first = true;
70 if (first) {
71 first = false;
72 SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBaseKit,"BaseKit");
73 }
74}
75
76// Constructor
78 SO_KIT_CONSTRUCTOR(SoDetectorTreeKit);
79
80 SO_NODE_ADD_FIELD(alternateRep, (NULL));
81
82 SO_KIT_ADD_CATALOG_ENTRY ( topSeparator, SoSeparator, FALSE, this,\0, FALSE);
83 SO_KIT_ADD_CATALOG_ENTRY ( pickStyle, SoSeparator, TRUE , topSeparator,\0, TRUE);
84 SO_KIT_ADD_CATALOG_ENTRY ( appearance, SoAppearanceKit, TRUE, topSeparator ,\0, TRUE);
85 SO_KIT_ADD_CATALOG_ENTRY ( units, SoUnits, TRUE, topSeparator ,\0, TRUE);
86 SO_KIT_ADD_CATALOG_ENTRY ( transform, SoTransform, TRUE , topSeparator,\0, TRUE);
87 SO_KIT_ADD_CATALOG_ENTRY (texture2Transform, SoTexture2Transform, TRUE, topSeparator ,\0, TRUE);
88 SO_KIT_ADD_CATALOG_ENTRY ( childList, SoSwitch, FALSE, topSeparator,\0, FALSE);
89 SO_KIT_ADD_CATALOG_ENTRY ( previewSeparator, SoSeparator, FALSE, childList,\0, TRUE);
90 SO_KIT_ADD_CATALOG_ENTRY ( fullSeparator, SoSeparator, FALSE, childList,\0, TRUE);
91
92 SO_KIT_INIT_INSTANCE();
93 createInitialTree();
94}
95
96// Destructor
98}
99
100
101SbBool SoDetectorTreeKit::affectsState() const {
102 return FALSE;
103}
104
105void SoDetectorTreeKit::createInitialTree() {
106
107 SoEventCallback *myCallback = new SoEventCallback();
108 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
109 SoDetectorTreeKit::expand,
110 this);
111 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
112 SoDetectorTreeKit::contract ,
113 this);
114 if(setPart("callbackList[0]",myCallback)==FALSE) myCallback->unref();
115
116 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
117 theChildList->whichChild.setValue(0);
118}
119
120void SoDetectorTreeKit::expand(void *userData, SoEventCallback *eventCB){
121
122 // Was the event previously handled? Is it the right kind?
123
124 if (eventCB->isHandled()) return;
125 const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
126 if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
127 if (!event->wasCtrlDown()) return;
128 if (event->wasShiftDown()) return;
129
130 // Which Detector is this being called for?
132
133 // Find out whether that's the one that has been picked.
134 // "This' is the lowest detector tree kit in the hierarchy.
135 SoHandleEventAction *handleEventAction = eventCB->getAction();
136 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
137 if (!pickedPoint) return;
138
139 SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
140 SoNode *ancestorNode=NULL;
141 for (int i=0;i<path->getLength();i++) {
142 ancestorNode = path->getNodeFromTail(i);
143 if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) break;
144 }
145 if (This!=ancestorNode) return;
146 // if (!ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) return;
147
148 // Deactivate the Preview
149 This->setPreview(FALSE);
150 eventCB->setHandled();
151
152}
153
154void SoDetectorTreeKit::contract(void *userData, SoEventCallback *eventCB){
155
156 // Was the event previously handled? Is it the right kind?
157 if (eventCB->isHandled()) return;
158 const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
159 if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
160 if (event->wasCtrlDown()) return;
161 if (!event->wasShiftDown()) return;
162
163 // Which Detector is this being called for?
165
166 // Find out whether that's the one that has been picked
167 SoHandleEventAction *handleEventAction = eventCB->getAction();
168 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
169 if (!pickedPoint) return;
170
171 // Find out whether that's the one that has been picked.
172 // "This" is the lowest detector tree kit in the hierarchy.
173 SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
174 SoNode *ancestorNode=NULL;
175 SbBool firstTreeFound=FALSE;
176 for (int i=0;i<path->getLength();i++) {
177 ancestorNode = path->getNodeFromTail(i);
178 if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) {
179 if (!firstTreeFound) {
180 if (This!=ancestorNode) return;
181 firstTreeFound=TRUE;
182 }
183 SoDetectorTreeKit *That = (SoDetectorTreeKit *) ancestorNode;
184 if (!That->getPreview()) {
185 That->setPreview(TRUE);
186 eventCB->setHandled();
187 return;
188 }
189 }
190 }
191}
192
193void SoDetectorTreeKit::setPreview(SbBool Flag) {
194 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
195 if (Flag) {
196 theChildList->whichChild.setValue(0);
197 }
198 else {
199 theChildList->whichChild.setValue(1);
200 }
201}
202
203SbBool SoDetectorTreeKit::getPreview() const {
204 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
205 if (theChildList->whichChild.getValue()==0) return TRUE;
206 return FALSE;
207}
208
209
211 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
212 theChildList->whichChild.setValue(SO_SWITCH_ALL);
213}
214
215SoSeparator *SoDetectorTreeKit::getPreviewSeparator() const {
216 return (SoSeparator *) previewSeparator.getValue();
217}
218
219SoSeparator *SoDetectorTreeKit::getFullSeparator() const {
220 return (SoSeparator *) fullSeparator.getValue();
221}
222
223
224
225
226// generateAlternateRep
228 alternateRep.setValue(topSeparator.getValue());
229}
230
232 alternateRep.setValue(NULL);
233}
234//////////////////////////////////////////////////////////////////////////////
236 SoAction* aAction
237)
238//////////////////////////////////////////////////////////////////////////////
239//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
240{
242 SoBaseKit::doAction(aAction);
243}
244
245#endif
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
#define SO_ALTERNATEREP_DO_ACTION(aAction)
virtual SoSeparator * getPreviewSeparator() const
virtual SoSeparator * getFullSeparator() const
void setPreviewAndFull()
virtual ~SoDetectorTreeKit()
static void initClass()
virtual SbBool getPreview() const
virtual SbBool affectsState() const
virtual void generateAlternateRep()
virtual void doAction(SoAction *)
virtual void clearAlternateRep()
virtual void setPreview(SbBool Flag)
#define userData
Definition: xmlparse.cc:572