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_search_action 5 #define tools_sg_search_action 6 7 #include "action" 8 9 #include <vector> 10 11 namespace tools { 12 namespace sg { 13 class node; 14 }} 15 16 namespace tools { 17 namespace sg { 18 19 class search_action : public action { 20 TOOLS_ACTION(search_action,tools::sg::search_action,action) 21 public: 22 search_action(std::ostream& a_out) 23 :parent(a_out) 24 ,m_what(search_node_of_class) 25 ,m_stop_at_first(false) 26 ,m_node(0) //not owner 27 28 ,m_done(false) 29 {} 30 virtual ~search_action(){} 31 public: 32 search_action(const search_action& a_from) 33 :parent(a_from) 34 ,m_what(a_from.m_what) 35 ,m_stop_at_first(a_from.m_stop_at_first) 36 ,m_class(a_from.m_class) 37 ,m_node(a_from.m_node) 38 39 ,m_done(false) 40 {} 41 search_action& operator=(const search_action& a_from){ 42 parent::operator=(a_from); 43 if(&a_from==this) return *this; 44 m_what = a_from.m_what; 45 m_stop_at_first = a_from.m_stop_at_first; 46 m_class = a_from.m_class; 47 m_node = a_from.m_node; 48 reset(); 49 return *this; 50 } 51 public: 52 void reset() { 53 m_done = false; 54 m_objs.clear(); 55 m_path.clear(); 56 m_paths.clear(); 57 } 58 59 enum search_what { 60 search_node_of_class = 0, 61 search_path_to_node = 1, 62 search_path_to_node_of_class = 2 63 }; 64 search_what what() const {return m_what;} 65 void set_what(search_what a_v) {m_what = a_v;} 66 67 void set_done(bool a_value) {m_done = a_value;} 68 bool done() const {return m_done;} 69 70 bool stop_at_first() const {return m_stop_at_first;} 71 void set_stop_at_first(bool a_v) {m_stop_at_first = a_v;} 72 73 ////////////////////////////////////////////////////////// 74 /// search_node_of_class : /////////////////////////////// 75 ////////////////////////////////////////////////////////// 76 //NOTE : result of a search is not necessary a sg::node. 77 // (For exa in ioda::main, could be a base_button). 78 void add_obj(void* a_obj) {m_objs.push_back(a_obj);} 79 const std::vector<void*>& objs() const {return m_objs;} 80 81 void set_class(const std::string& a_class) {m_class = a_class;} 82 const std::string& sclass() const {return m_class;} 83 84 ////////////////////////////////////////////////////////// 85 /// search_path_to_node : //////////////////////////////// 86 ////////////////////////////////////////////////////////// 87 void set_node(sg::node* a_v) {m_node = a_v;} 88 sg::node* node() const {return m_node;} 89 90 void path_push(sg::node* a_v) {m_path.push_back(a_v);} 91 void path_pop() {m_path.pop_back();} 92 93 typedef std::vector<sg::node*> path_t; 94 const path_t& path() const {return m_path;} 95 //path_t path() {return m_path;} 96 void clear_path() {m_path.clear();} 97 98 bool do_path() const { 99 if(m_what==search_action::search_path_to_node) return true; 100 if(m_what==search_action::search_path_to_node_of_class) return true; 101 return false; 102 } 103 104 ////////////////////////////////////////////////////////// 105 /// search_path_to_node_of_class : /////////////////////// 106 ////////////////////////////////////////////////////////// 107 void add_path(const path_t& a_p) {m_paths.push_back(a_p);} 108 109 typedef std::vector<path_t> paths_t; 110 const paths_t& paths() const {return m_paths;} 111 112 protected: 113 search_what m_what; 114 bool m_stop_at_first; 115 116 //search_node_of_class : 117 std::string m_class; 118 std::vector<void*> m_objs; 119 120 //search_path_to_node : 121 sg::node* m_node; //not owner. 122 path_t m_path; 123 124 //search_path_to_node_of_class : 125 std::vector<path_t> m_paths; 126 127 bool m_done; 128 }; 129 130 }} 131 132 #endif