SoCounterAction.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 #ifdef G4VIS_BUILD_OI_DRIVER
00027 
00028 /*----------------------------HEPVis----------------------------------------*/
00029 /*                                                                          */
00030 /* Node:             SoCounterAction                                        */
00031 /* Author:           Guy Barrand                                            */
00032 /*                                                                          */
00033 /*--------------------------------------------------------------------------*/
00034 
00035 // this :
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   //printf("debug : begin : %s %s\n",aNode->getName().getString(),
00064     //aNode->getTypeId().getName().getString());
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

Generated on Mon May 27 17:50:34 2013 for Geant4 by  doxygen 1.4.7