38 #ifdef G4VIS_BUILD_OI_DRIVER
41 #include "HEPVis/nodekits/SoDetectorTreeKit.h"
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>
61 #include <HEPVis/actions/SoAlternateRepAction.h>
66 SO_KIT_SOURCE(SoDetectorTreeKit)
69 void SoDetectorTreeKit::initClass(){
70 SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBaseKit,
"BaseKit");
74 SoDetectorTreeKit::SoDetectorTreeKit() {
75 SO_KIT_CONSTRUCTOR(SoDetectorTreeKit);
77 SO_NODE_ADD_FIELD(alternateRep, (NULL));
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);
89 SO_KIT_INIT_INSTANCE();
94 SoDetectorTreeKit::~SoDetectorTreeKit() {
98 SbBool SoDetectorTreeKit::affectsState()
const {
102 void SoDetectorTreeKit::createInitialTree() {
104 SoEventCallback *myCallback =
new SoEventCallback();
105 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
106 SoDetectorTreeKit::expand,
108 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
109 SoDetectorTreeKit::contract ,
111 if(setPart(
"callbackList[0]",myCallback)==
FALSE) myCallback->unref();
113 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
114 theChildList->whichChild.setValue(0);
117 void SoDetectorTreeKit::expand(
void *
userData, SoEventCallback *eventCB){
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;
128 SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
132 SoHandleEventAction *handleEventAction = eventCB->getAction();
133 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
134 if (!pickedPoint)
return;
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;
142 if (This!=ancestorNode)
return;
146 This->setPreview(
FALSE);
147 eventCB->setHandled();
151 void SoDetectorTreeKit::contract(
void *userData, SoEventCallback *eventCB){
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;
161 SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
164 SoHandleEventAction *handleEventAction = eventCB->getAction();
165 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
166 if (!pickedPoint)
return;
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;
180 SoDetectorTreeKit *That = (SoDetectorTreeKit *) ancestorNode;
181 if (!That->getPreview()) {
182 That->setPreview(
TRUE);
183 eventCB->setHandled();
190 void SoDetectorTreeKit::setPreview(SbBool Flag) {
191 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
193 theChildList->whichChild.setValue(0);
196 theChildList->whichChild.setValue(1);
200 SbBool SoDetectorTreeKit::getPreview()
const {
201 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
202 if (theChildList->whichChild.getValue()==0)
return TRUE;
207 void SoDetectorTreeKit::setPreviewAndFull() {
208 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
209 theChildList->whichChild.setValue(SO_SWITCH_ALL);
212 SoSeparator *SoDetectorTreeKit::getPreviewSeparator()
const {
213 return (SoSeparator *) previewSeparator.getValue();
216 SoSeparator *SoDetectorTreeKit::getFullSeparator()
const {
217 return (SoSeparator *) fullSeparator.getValue();
224 void SoDetectorTreeKit::generateAlternateRep() {
225 alternateRep.setValue(topSeparator.getValue());
228 void SoDetectorTreeKit::clearAlternateRep() {
229 alternateRep.setValue(NULL);
232 void SoDetectorTreeKit::doAction(
238 SO_ALTERNATEREP_DO_ACTION(aAction)
239 SoBaseKit::doAction(aAction);