00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifdef G4VIS_BUILD_OI_DRIVER
00039
00040
00041 #include "HEPVis/nodekits/SoDetectorTreeKit.h"
00042
00043 #include <Inventor/SoPickedPoint.h>
00044 #include <Inventor/nodes/SoSeparator.h>
00045 #include <Inventor/nodes/SoPickStyle.h>
00046 #include <Inventor/nodes/SoDrawStyle.h>
00047 #include <Inventor/nodes/SoSwitch.h>
00048 #include <Inventor/nodes/SoMaterial.h>
00049 #include <Inventor/nodes/SoUnits.h>
00050 #include <Inventor/nodes/SoTransform.h>
00051 #include <Inventor/nodes/SoEventCallback.h>
00052 #include <Inventor/nodekits/SoSeparatorKit.h>
00053 #include <Inventor/nodekits/SoShapeKit.h>
00054 #include <Inventor/nodekits/SoAppearanceKit.h>
00055 #include <Inventor/nodekits/SoNodeKitListPart.h>
00056 #include <Inventor/nodekits/SoBaseKit.h>
00057 #include <Inventor/nodes/SoTexture2Transform.h>
00058 #include <Inventor/events/SoMouseButtonEvent.h>
00059 #include <Inventor/actions/SoHandleEventAction.h>
00060
00061 #include <HEPVis/actions/SoAlternateRepAction.h>
00062
00063 #include <cmath>
00064
00065
00066 SO_KIT_SOURCE(SoDetectorTreeKit)
00067
00068
00069 void SoDetectorTreeKit::initClass(){
00070 SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBaseKit,"BaseKit");
00071 }
00072
00073
00074 SoDetectorTreeKit::SoDetectorTreeKit() {
00075 SO_KIT_CONSTRUCTOR(SoDetectorTreeKit);
00076
00077 SO_NODE_ADD_FIELD(alternateRep, (NULL));
00078
00079 SO_KIT_ADD_CATALOG_ENTRY ( topSeparator, SoSeparator, FALSE, this,\0, FALSE);
00080 SO_KIT_ADD_CATALOG_ENTRY ( pickStyle, SoSeparator, TRUE , topSeparator,\0, TRUE);
00081 SO_KIT_ADD_CATALOG_ENTRY ( appearance, SoAppearanceKit, TRUE, topSeparator ,\0, TRUE);
00082 SO_KIT_ADD_CATALOG_ENTRY ( units, SoUnits, TRUE, topSeparator ,\0, TRUE);
00083 SO_KIT_ADD_CATALOG_ENTRY ( transform, SoTransform, TRUE , topSeparator,\0, TRUE);
00084 SO_KIT_ADD_CATALOG_ENTRY (texture2Transform, SoTexture2Transform, TRUE, topSeparator ,\0, TRUE);
00085 SO_KIT_ADD_CATALOG_ENTRY ( childList, SoSwitch, FALSE, topSeparator,\0, FALSE);
00086 SO_KIT_ADD_CATALOG_ENTRY ( previewSeparator, SoSeparator, FALSE, childList,\0, TRUE);
00087 SO_KIT_ADD_CATALOG_ENTRY ( fullSeparator, SoSeparator, FALSE, childList,\0, TRUE);
00088
00089 SO_KIT_INIT_INSTANCE();
00090 createInitialTree();
00091 }
00092
00093
00094 SoDetectorTreeKit::~SoDetectorTreeKit() {
00095 }
00096
00097
00098 SbBool SoDetectorTreeKit::affectsState() const {
00099 return FALSE;
00100 }
00101
00102 void SoDetectorTreeKit::createInitialTree() {
00103
00104 SoEventCallback *myCallback = new SoEventCallback();
00105 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
00106 SoDetectorTreeKit::expand,
00107 this);
00108 myCallback->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
00109 SoDetectorTreeKit::contract ,
00110 this);
00111 if(setPart("callbackList[0]",myCallback)==FALSE) myCallback->unref();
00112
00113 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
00114 theChildList->whichChild.setValue(0);
00115 }
00116
00117 void SoDetectorTreeKit::expand(void *userData, SoEventCallback *eventCB){
00118
00119
00120
00121 if (eventCB->isHandled()) return;
00122 const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
00123 if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
00124 if (!event->wasCtrlDown()) return;
00125 if (event->wasShiftDown()) return;
00126
00127
00128 SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
00129
00130
00131
00132 SoHandleEventAction *handleEventAction = eventCB->getAction();
00133 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
00134 if (!pickedPoint) return;
00135
00136 SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
00137 SoNode *ancestorNode=NULL;
00138 for (int i=0;i<path->getLength();i++) {
00139 ancestorNode = path->getNodeFromTail(i);
00140 if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) break;
00141 }
00142 if (This!=ancestorNode) return;
00143
00144
00145
00146 This->setPreview(FALSE);
00147 eventCB->setHandled();
00148
00149 }
00150
00151 void SoDetectorTreeKit::contract(void *userData, SoEventCallback *eventCB){
00152
00153
00154 if (eventCB->isHandled()) return;
00155 const SoMouseButtonEvent *event= (SoMouseButtonEvent *) eventCB->getEvent();
00156 if (!SoMouseButtonEvent::isButtonPressEvent(event,SoMouseButtonEvent::BUTTON1)) return;
00157 if (event->wasCtrlDown()) return;
00158 if (!event->wasShiftDown()) return;
00159
00160
00161 SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
00162
00163
00164 SoHandleEventAction *handleEventAction = eventCB->getAction();
00165 const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
00166 if (!pickedPoint) return;
00167
00168
00169
00170 SoFullPath* path = (SoFullPath*)pickedPoint->getPath();
00171 SoNode *ancestorNode=NULL;
00172 SbBool firstTreeFound=FALSE;
00173 for (int i=0;i<path->getLength();i++) {
00174 ancestorNode = path->getNodeFromTail(i);
00175 if (ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) {
00176 if (!firstTreeFound) {
00177 if (This!=ancestorNode) return;
00178 firstTreeFound=TRUE;
00179 }
00180 SoDetectorTreeKit *That = (SoDetectorTreeKit *) ancestorNode;
00181 if (!That->getPreview()) {
00182 That->setPreview(TRUE);
00183 eventCB->setHandled();
00184 return;
00185 }
00186 }
00187 }
00188 }
00189
00190 void SoDetectorTreeKit::setPreview(SbBool Flag) {
00191 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
00192 if (Flag) {
00193 theChildList->whichChild.setValue(0);
00194 }
00195 else {
00196 theChildList->whichChild.setValue(1);
00197 }
00198 }
00199
00200 SbBool SoDetectorTreeKit::getPreview() const {
00201 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
00202 if (theChildList->whichChild.getValue()==0) return TRUE;
00203 return FALSE;
00204 }
00205
00206
00207 void SoDetectorTreeKit::setPreviewAndFull() {
00208 SoSwitch *theChildList = (SoSwitch *) childList.getValue();
00209 theChildList->whichChild.setValue(SO_SWITCH_ALL);
00210 }
00211
00212 SoSeparator *SoDetectorTreeKit::getPreviewSeparator() const {
00213 return (SoSeparator *) previewSeparator.getValue();
00214 }
00215
00216 SoSeparator *SoDetectorTreeKit::getFullSeparator() const {
00217 return (SoSeparator *) fullSeparator.getValue();
00218 }
00219
00220
00221
00222
00223
00224 void SoDetectorTreeKit::generateAlternateRep() {
00225 alternateRep.setValue(topSeparator.getValue());
00226 }
00227
00228 void SoDetectorTreeKit::clearAlternateRep() {
00229 alternateRep.setValue(NULL);
00230 }
00232 void SoDetectorTreeKit::doAction(
00233 SoAction* aAction
00234 )
00237 {
00238 SO_ALTERNATEREP_DO_ACTION(aAction)
00239 SoBaseKit::doAction(aAction);
00240 }
00241
00242 #endif