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