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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/sg/group (Version 11.3.0) and /externals/g4tools/include/tools/sg/group (Version 3.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_sg_group                            
  5 #define tools_sg_group                            
  6                                                   
  7 //#define TOOLS_SG_GROUP_DEBUG                    
  8                                                   
  9 #include "node"                                   
 10                                                   
 11 #include "pick_action"                            
 12 #include "event_action"                           
 13                                                   
 14 #ifdef TOOLS_SG_GROUP_DEBUG                       
 15 #include "render_action"                          
 16 #endif                                            
 17                                                   
 18 namespace tools {                                 
 19 namespace sg {                                    
 20                                                   
 21 class group : public node {                       
 22   TOOLS_NODE(group,tools::sg::group,node)         
 23 public:                                           
 24   virtual void render(render_action& a_action)    
 25 #ifdef TOOLS_SG_GROUP_DEBUG                       
 26     std::ostream& out = a_action.out();           
 27     tools_vforcit(node*,m_children,it) {          
 28       out << "debug : tools::sg::group::render    
 29       (*it)->render(a_action);                    
 30       out << "debug : tools::sg::group::render    
 31     }                                             
 32 #else                                             
 33     tools_vforcit(node*,m_children,it) (*it)->    
 34 #endif                                            
 35   }                                               
 36   virtual void pick(pick_action& a_action) {      
 37     tools_vforcit(node*,m_children,it) {          
 38       (*it)->pick(a_action);                      
 39       if(a_action.done()) break;                  
 40     }                                             
 41   }                                               
 42   virtual void bbox(bbox_action& a_action) {      
 43     tools_vforcit(node*,m_children,it) (*it)->    
 44   }                                               
 45   virtual void event(event_action& a_action) {    
 46     tools_vforcit(node*,m_children,it) {          
 47       (*it)->event(a_action);                     
 48       if(a_action.done()) break;                  
 49     }                                             
 50   }                                               
 51   virtual void search(search_action& a_action)    
 52     parent::search(a_action);                     
 53     if(a_action.done()) return;                   
 54     if(a_action.do_path()) a_action.path_push(    
 55     tools_vforcit(node*,m_children,it) {          
 56       (*it)->search(a_action);                    
 57       if(a_action.done()) return;                 
 58     }                                             
 59     if(a_action.do_path()) a_action.path_pop()    
 60   }                                               
 61   virtual void get_matrix(get_matrix_action& a    
 62     tools_vforcit(node*,m_children,it) {          
 63       (*it)->get_matrix(a_action);                
 64       if(a_action.done()) return;                 
 65     }                                             
 66   }                                               
 67   virtual bool write(write_action& a_action) {    
 68     if(!a_action.beg_node(*this)) return false    
 69     if(!write_fields(a_action)) return false;     
 70     if(!write_children(a_action)) return false    
 71     if(!a_action.end_node(*this)) return false    
 72     return true;                                  
 73   }                                               
 74   virtual void is_visible(visible_action& a_ac    
 75     tools_vforcit(node*,m_children,it) {          
 76       (*it)->is_visible(a_action);                
 77     }                                             
 78   }                                               
 79 public:                                           
 80   group():node(){}                                
 81   virtual ~group(){clear();}                      
 82 public:                                           
 83   group(const group& a_from)                      
 84   :node(a_from)                                   
 85   {                                               
 86     tools_vforcit(node*,a_from.m_children,it)     
 87   }                                               
 88   group& operator=(const group& a_from){          
 89     node::operator=(a_from);                      
 90     if(&a_from==this) return *this;               
 91     clear();                                      
 92     tools_vforcit(node*,a_from.m_children,it)     
 93     return *this;                                 
 94   }                                               
 95 public:                                           
 96   void add(node* a_node) {                        
 97     //WARNING :  take ownership of a_node.        
 98     m_children.push_back(a_node);                 
 99   }                                               
100   void add_front(node* a_node) {                  
101     //WARNING :  take ownership of a_node.        
102     m_children.insert(m_children.begin(),a_nod    
103   }                                               
104   void set(unsigned int a_index,node* a_node)     
105     //WARNING :  take ownership of a_node.        
106     //WARNING : no check is done on a_index.      
107     m_children[a_index] = a_node;                 
108   }                                               
109                                                   
110   bool replace(const node* a_from,node* a_to,b    
111     tools_vforit(node*,m_children,it) {           
112       if((*it)==a_from) {                         
113         node* old = *it;                          
114         (*it) = a_to;                             
115         if(a_del) delete old;                     
116         return true;                              
117       }                                           
118     }                                             
119     return false;                                 
120   }                                               
121                                                   
122   void swap(unsigned int a_1,unsigned int a_2)    
123     // WARNING : no check is done on a_1,a_2.     
124     node* tmp = m_children[a_1];                  
125     m_children[a_1] = m_children[a_2];            
126     m_children[a_2] = tmp;                        
127   }                                               
128                                                   
129   template <class T>                              
130   T* search() const {                             
131     tools_vforcit(node*,m_children,it) {          
132       T* o = safe_cast<node,T>(*(*it));           
133       if(o) return o;                             
134     }                                             
135     return 0;                                     
136   }                                               
137                                                   
138 /*                                                
139   template <class T>                              
140   T* rsearch_from(const node* a_node) const {     
141     bool found = false;                           
142     tools_vforcrit(node*,m_children,it) {         
143       // the below logic permits to test a_nod    
144       if(!found) {if(*it==a_node) found = true    
145       if(found) {                                 
146         T* o = safe_cast<node,T>(*(*it));         
147         if(o) return o;                           
148       }                                           
149     }                                             
150     return 0;                                     
151   }                                               
152 */                                                
153                                                   
154   void* rsearch_from(const node* a_node,          
155                      const std::string& a_clas    
156                      bool a_inc_a_node = true)    
157     bool found = false;                           
158     tools_vforcrit(node*,m_children,it) {         
159       // the below logic permits to test a_nod    
160       if(!found) {                                
161         if(*it==a_node) {                         
162           found = true;                           
163           if(!a_inc_a_node) continue; //skip a    
164         }                                         
165       }                                           
166       if(found) {                                 
167         void* p = (*it)->cast(a_class);           
168         if(p) return p;                           
169       }                                           
170     }                                             
171     return 0;                                     
172   }                                               
173                                                   
174   bool remove(const node* a_node){                
175     //NOTE : no delete on a_node is performed.    
176     tools_vforit(node*,m_children,it) {           
177       if(a_node==(*it)) {                         
178         m_children.erase(it);                     
179         return true;                              
180       }                                           
181     }                                             
182     return false;                                 
183   }                                               
184                                                   
185   bool remove_index(unsigned int a_index){        
186     //NOTE : no delete on node at a_index is p    
187     std::vector<node*>::iterator it = m_childr    
188     it += a_index;                                
189     if(it>=m_children.end()) return false;        
190     m_children.erase(it);                         
191     return true;                                  
192   }                                               
193                                                   
194   bool delete_from(const node* a_node,bool a_i    
195     bool found = false;                           
196     std::vector<node*>::iterator it;              
197     for(it=m_children.begin();it!=m_children.e    
198       if(!found) {                                
199         if(*it==a_node) {                         
200           found = true;                           
201           if(!a_inc_a_node) {it++;continue;} /    
202         }                                         
203       }                                           
204       if(found) {                                 
205         node* old = *it;                          
206         it = m_children.erase(it);                
207         delete old;                               
208       } else {                                    
209         it++;                                     
210       }                                           
211     }                                             
212     return found;                                 
213   }                                               
214                                                   
215   void transfer(group& a_from) {                  
216     if(&a_from==this) return;                     
217     clear();                                      
218     m_children.resize(a_from.size());             
219     std::vector<node*>::iterator it  = m_child    
220     std::vector<node*>::iterator fit = a_from.    
221     for(;fit!=a_from.m_children.end();++it,++f    
222       *it = *fit;                                 
223       *fit = 0;                                   
224     }                                             
225     a_from.m_children.clear();                    
226   }                                               
227                                                   
228   void transfer(std::vector<node*>& a_to) {       
229     a_to = m_children;                            
230     m_children.clear();                           
231     //touch();                                    
232   }                                               
233                                                   
234 //void clear() {safe_clear<node>(m_children);}    
235   void clear() {safe_reverse_clear<node>(m_chi    
236                                                   
237   void raw_clear() { //used for sg coming from    
238     tools::raw_clear<node>(m_children); //tool    
239   }                                               
240                                                   
241 //void children_clear() {m_children.clear();}     
242                                                   
243   size_t size() const {return m_children.size(    
244   bool empty() const {return m_children.size()    
245   node* operator[](size_t a_index) const{         
246     //WARNING : no check is done on a_index.      
247     return m_children[a_index];                   
248   }                                               
249   const std::vector<node*>& children() const {    
250   std::vector<node*>& children() {return m_chi    
251                                                   
252   bool insert(unsigned int a_index,node* a_new    
253     if(a_index==m_children.size()) {              
254       m_children.push_back(a_new);                
255       return true;                                
256     }                                             
257     unsigned int index = 0;                       
258     std::vector<node*>::iterator it;              
259     for(it=m_children.begin();it!=m_children.e    
260       if(index==a_index) {                        
261         m_children.insert(it,a_new);              
262         return true;                              
263       }                                           
264     }                                             
265     return false;                                 
266   }                                               
267 /*                                                
268   bool insert(const node* a_from,node* a_new){    
269     tools_vforit(node*,m_children,it) {           
270       if((*it)==a_from) {                         
271         m_children.insert(it,a_new);              
272         return true;                              
273       }                                           
274     }                                             
275     return false;                                 
276   }                                               
277 */                                                
278   template <class T>                              
279   T* rsearch() const { //used in agora.           
280     tools_vforcrit(node*,m_children,it) {         
281       T* o = safe_cast<node,T>(*(*it));           
282       if(o) return o;                             
283     }                                             
284     return 0;                                     
285   }                                               
286                                                   
287   bool position(const node* a_node,unsigned in    
288     a_index = 0;                                  
289     tools_vforcit(node*,m_children,it) {          
290       if(a_node==(*it)) return true;              
291       a_index++;                                  
292     }                                             
293     return false;                                 
294   }                                               
295                                                   
296   node* node_at(unsigned int a_index) const {     
297     if(a_index>=m_children.size()) return 0;      
298     return m_children[a_index];                   
299   }                                               
300                                                   
301   template <class T>                              
302   T* child(unsigned int a_index) const {          
303     if(a_index>=m_children.size()) return 0;      
304     node* _node = m_children[a_index];            
305     if(!_node) return 0;                          
306     return safe_cast<node,T>(*_node);             
307   }                                               
308                                                   
309                                                   
310 protected:                                        
311   bool write_children(write_action& a_action)     
312     tools_vforcit(node*,m_children,it) {          
313       if(!(*it)->write(a_action)) return false    
314     }                                             
315     return true;                                  
316   }                                               
317 protected:                                        
318   std::vector<node*> m_children;                  
319 };                                                
320                                                   
321 }}                                                
322                                                   
323 #endif