Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/_switch is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg__switch
0005 #define tools_sg__switch
0006 
0007 // NOTE : "switch" is a C/C++ keyword. Have "_switch" as a class name.
0008 
0009 #include "group"
0010 #include "sf"
0011 
0012 namespace tools {
0013 namespace sg {
0014 
0015 class _switch : public group {
0016   TOOLS_NODE(_switch,tools::sg::_switch,group)
0017 public:
0018   sf<int> which;
0019 public:
0020   virtual const desc_fields& node_desc_fields() const {
0021     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::_switch)
0022     static const desc_fields s_v(parent::node_desc_fields(),1, //WARNING : take care of count.
0023       TOOLS_ARG_FIELD_DESC(which)
0024     );
0025     return s_v;
0026   }
0027 private:
0028   void add_fields(){
0029     add_field(&which);
0030   }
0031 public: //node
0032   virtual void render(render_action& a_action) {
0033     int index = which.value();
0034     if(index==(-1)) {
0035       group::render(a_action);
0036     } else if((index>=0)&&(index<(int)m_children.size())) {
0037       m_children[index]->render(a_action);
0038     }
0039   }
0040   virtual void pick(pick_action& a_action) {
0041     int index = which.value();
0042     if(index==(-1)) {
0043       group::pick(a_action);
0044     } else if((index>=0)&&(index<(int)m_children.size())) {
0045       m_children[index]->pick(a_action);
0046     }
0047   }
0048   virtual void bbox(bbox_action& a_action) {
0049     int index = which.value();
0050     if(index==(-1)) {
0051       group::bbox(a_action);
0052     } else if((index>=0)&&(index<(int)m_children.size())) {
0053       m_children[index]->bbox(a_action);
0054     }
0055   }
0056   virtual void search(search_action& a_action) {
0057     int index = which.value();
0058     if(index==(-1)) {
0059       group::search(a_action);
0060     } else if((index>=0)&&(index<(int)m_children.size())) {
0061       if(a_action.do_path()) a_action.path_push(this);
0062       m_children[index]->search(a_action);
0063       if(a_action.done()) return;
0064       if(a_action.do_path()) a_action.path_pop();
0065     }
0066   }
0067   virtual void event(event_action& a_action) {
0068     if(a_action.do_switch_children()) {
0069       group::event(a_action);
0070     } else {
0071       int index = which.value();
0072       if(index==(-1)){
0073         group::event(a_action);
0074       } else if((index>=0)&&(index<(int)m_children.size())) {
0075         m_children[index]->event(a_action);
0076       }
0077     }
0078   }
0079   virtual bool write(write_action& a_action) {
0080     if(!a_action.beg_node(*this)) return false;
0081     if(!write_fields(a_action)) return false;
0082 
0083     if(a_action.switch_do_all_children()) { //for exam write_exsg
0084       if(!write_children(a_action)) return false;
0085     } else { //for exa write_gl2ps
0086       int index = which.value();
0087       if(index==(-1)) {
0088         if(!write_children(a_action)) return false;
0089       } else if((index>=0)&&(index<(int)m_children.size())) {
0090         m_children[index]->write(a_action);
0091       }
0092     }
0093     if(!a_action.end_node(*this)) return false;
0094     return true;
0095   }
0096 public:
0097   _switch()
0098   :group()
0099   ,which(-1)
0100   {
0101     add_fields();
0102   }
0103   virtual ~_switch(){}
0104 public:
0105   _switch(const _switch& a_from)
0106   :group(a_from)
0107   ,which(a_from.which)
0108   {
0109     add_fields();
0110   }
0111   _switch& operator=(const _switch& a_from){
0112     group::operator=(a_from);
0113     which = a_from.which;
0114     return *this;
0115   }
0116 public:
0117   node* which_node() const {
0118     int index = which.value();
0119     if(index<0) return 0;
0120     if(index>=(int)m_children.size()) return 0;
0121     return m_children[index];
0122   }
0123 };
0124 
0125 }}
0126 
0127 #endif