SoDetectorTreeKit.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 //
00027 //
00028 // $Id$
00029 //
00030 /*-----------------------------HEPVis----------------------------------------*/
00031 /*                                                                           */
00032 /* Node:             SoDetectorTreeKit                                       */
00033 /* Description:      Represents a single sided silicon strip detector        */
00034 /* Author:           Joe Boudreau Nov 11 1996                                */
00035 /*                                                                           */
00036 /*---------------------------------------------------------------------------*/
00037 
00038 #ifdef G4VIS_BUILD_OI_DRIVER
00039 
00040 // this :
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 // This statement is required
00066 SO_KIT_SOURCE(SoDetectorTreeKit)
00067  
00068 // initClass
00069 void SoDetectorTreeKit::initClass(){
00070   SO_KIT_INIT_CLASS(SoDetectorTreeKit,SoBaseKit,"BaseKit");
00071 }
00072 
00073 // Constructor
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 // Destructor
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   // Was the event previously handled? Is it the right kind?
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   // Which Detector is this being called for?
00128   SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
00129 
00130   // Find out whether that's the one that has been picked.  
00131   // "This' is the lowest detector tree kit in the hierarchy.
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   //  if (!ancestorNode->isOfType(SoDetectorTreeKit::getClassTypeId())) return;
00144  
00145   // Deactivate the Preview
00146   This->setPreview(FALSE);
00147   eventCB->setHandled();
00148      
00149 }
00150 
00151 void SoDetectorTreeKit::contract(void *userData, SoEventCallback *eventCB){
00152 
00153   // Was the event previously handled? Is it the right kind?
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   // Which Detector is this being called for?
00161   SoDetectorTreeKit* This = (SoDetectorTreeKit *) userData;
00162 
00163   // Find out whether that's the one that has been picked
00164   SoHandleEventAction *handleEventAction = eventCB->getAction();
00165   const SoPickedPoint *pickedPoint = handleEventAction->getPickedPoint();
00166   if (!pickedPoint) return;
00167  
00168   // Find out whether that's the one that has been picked.  
00169   // "This" is the lowest detector tree kit in the hierarchy.
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 // generateAlternateRep
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

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