Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_nodekit 5 #define tools_sg_nodekit 6 7 #include "pick_action" 8 #include "group" 9 10 namespace tools { 11 namespace sg { 12 13 inline void nodekit_pick(pick_action& a_action,node& a_sg,node* a_node) { 14 if(a_action.stop_at_first()){ 15 a_sg.pick(a_action); 16 if(a_action.done()) { 17 a_action.set_node(a_node); 18 a_action.save_state(a_action.state()); 19 } 20 } else { 21 // have a local pick_action to override node in the found pick list. 22 pick_action action(a_action); 23 a_sg.pick(action); 24 typedef pick_action::pick_t pick_t; 25 const std::vector<pick_t>& pks = action.picks(); 26 std::vector<pick_t>::const_iterator it; 27 for(it=pks.begin();it!=pks.end();++it) { 28 a_action.add_pick(*a_node,(*it).zs(),(*it).ws(),(*it).state()); 29 } 30 } 31 } 32 33 }} 34 35 #include "render_action" 36 #include "bbox_action" 37 38 namespace tools { 39 namespace sg { 40 41 class nodekit : public node { 42 TOOLS_HEADER(nodekit,tools::sg::nodekit,node) 43 public: 44 virtual void update_sg(std::ostream&) = 0; 45 public: 46 virtual void render(render_action& a_action) { 47 update_if_touched(a_action.out()); 48 m_group.render(a_action); 49 } 50 virtual void search(search_action& a_action) { 51 update_if_touched(a_action.out()); 52 parent::search(a_action); 53 if(a_action.done()) return; 54 m_group.search(a_action); 55 } 56 virtual void bbox(bbox_action& a_action) { 57 update_if_touched(a_action.out()); 58 m_group.bbox(a_action); 59 } 60 /* 61 virtual void pick(pick_action& a_action) { 62 update_if_touched(a_action.out()); 63 nodekit_pick(a_action,m_group,this); 64 } 65 virtual bool write(write_action& a_action) { 66 update_if_touched(a_action.out()); 67 //if(!write_fields(a_action)) return false; 68 return m_group.write(a_action); 69 } 70 */ 71 public: 72 nodekit() 73 :parent() 74 {} 75 virtual ~nodekit(){} 76 public: 77 nodekit(const nodekit& a_from) 78 :parent(a_from) 79 {} 80 nodekit& operator=(const nodekit& a_from){ 81 parent::operator=(a_from); 82 return *this; 83 } 84 protected: 85 void update_if_touched(std::ostream& a_out) { 86 if(touched()) { 87 update_sg(a_out); 88 reset_touched(); 89 } 90 } 91 protected: 92 group m_group; 93 }; 94 95 }} 96 97 #endif