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 #ifdef G4VIS_BUILD_OI_DRIVER
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #include <HEPVis/actions/SoCounterAction.h>
00037 
00038 #include <Inventor/nodes/SoNode.h>
00039 #include <Inventor/nodes/SoGroup.h>
00040 #include <Inventor/nodes/SoSwitch.h>
00041 #include <Inventor/nodekits/SoBaseKit.h>
00042 #include <Inventor/elements/SoSwitchElement.h>
00043 
00044 SO_ACTION_SOURCE(SoCounterAction)
00045 
00046 void SoCounterAction::initClass(void){
00047   SO_ACTION_INIT_CLASS(SoCounterAction,SoAction);
00048 
00049   SO_ENABLE(SoCounterAction,SoSwitchElement);
00050 
00051   SO_ACTION_ADD_METHOD(SoNode,SoCounterAction::actionMethod);
00052 }
00053 SoCounterAction::SoCounterAction()
00054 :fCount(0),fLookFor(NODE),fCheckDerived(TRUE){
00055   SO_ACTION_CONSTRUCTOR(SoCounterAction);
00056 }
00057 SoCounterAction::~SoCounterAction(){}
00058 void SoCounterAction::beginTraversal(SoNode* node){
00059   fCount = 0;
00060   SoAction::beginTraversal(node);
00061 }
00062 void SoCounterAction::actionMethod(SoAction* aThis,SoNode* aNode) {
00063   
00064     
00065   SoCounterAction* This = (SoCounterAction*)aThis;
00066   if(This->fLookFor==NODE) {
00067     This->fCount++;
00068   } else if(This->fLookFor==TYPE) {
00069     if(This->fCheckDerived==TRUE) {
00070       if(aNode->getTypeId().isDerivedFrom(This->fType)) This->fCount++;
00071     } else {
00072       if(aNode->getTypeId()==This->fType) This->fCount++;
00073     }
00074   } else if(This->fLookFor==NAME) {
00075     if(This->fName==aNode->getName()) This->fCount++;
00076   }
00077   if(aNode->isOfType(SoSwitch::getClassTypeId())) {
00078     SoSwitch* sw = (SoSwitch*)aNode;
00079     SbBool flag = sw->whichChild.enableNotify(FALSE);
00080     int old = sw->whichChild.getValue();
00081     sw->whichChild.setValue(SO_SWITCH_ALL);
00082     aNode->doAction(aThis);
00083     sw->whichChild.setValue(old);
00084     sw->whichChild.enableNotify(flag);
00085   } else if(aNode->isOfType(SoGroup::getClassTypeId())) {
00086     aNode->doAction(aThis);
00087   } else if(aNode->isOfType(SoBaseKit::getClassTypeId())) {
00088     aNode->doAction(aThis);
00089   }
00090 }
00091 void SoCounterAction::setLookFor(LookFor aLookFor) {
00092   fLookFor = aLookFor;
00093 }
00094 void SoCounterAction::setType(const SoType aType,SbBool aCheckDerived) {
00095   fType = aType;
00096   fCheckDerived = aCheckDerived;
00097 }
00098 void SoCounterAction::setName(const SbName aName){
00099   fName = aName;
00100 }
00101 int SoCounterAction::getCount() const {
00102   return fCount;
00103 }
00104 
00105 #endif