g4tools  5.4.0
Public Member Functions | Protected Member Functions | List of all members
tools::sg::node Class Referenceabstract
Inheritance diagram for tools::sg::node:
Inheritance graph
[legend]

Public Member Functions

virtual void * cast (const std::string &a_class) const
 
virtual const std::string & s_cls () const =0
 
virtual nodecopy () const =0
 
virtual unsigned int cls_version () const
 
virtual const desc_fieldsnode_desc_fields () const
 
virtual void render (render_action &)
 
virtual void pick (pick_action &)
 
virtual void bbox (bbox_action &)
 
virtual void search (search_action &a_action)
 
virtual void get_matrix (get_matrix_action &a_action)
 
virtual bool write (write_action &a_action)
 
virtual void event (event_action &)
 
virtual bool read (read_action &a_action)
 
virtual void is_visible (visible_action &)
 
virtual void protocol_one_fields (std::vector< field * > &a_fields) const
 
virtual bool draw_in_frame_buffer () const
 
virtual bool touched ()
 
virtual void reset_touched ()
 
 node ()
 
virtual ~node ()
 
void touch ()
 
fieldfield_from_desc (const field_desc &a_desc) const
 
void dump_field_descs (std::ostream &a_out) const
 
fieldfind_field_by_name (const std::string &a_name) const
 

Protected Member Functions

 node (const node &)
 
nodeoperator= (const node &)
 
void add_field (field *a_field)
 
bool write_fields (write_action &a_action)
 
bool read_fields (read_action &a_action)
 
field_desc::offset_t field_offset (const field *a_field) const
 
fieldfind_field (const field_desc &a_rdesc) const
 
void check_fields (std::ostream &a_out) const
 

Detailed Description

Definition at line 28 of file node.

Constructor & Destructor Documentation

◆ node() [1/2]

tools::sg::node::node ( )
inline

Definition at line 106 of file node.

107  {
108 #ifdef TOOLS_MEM
109  mem::increment(s_class().c_str());
110 #endif
111  }

◆ ~node()

virtual tools::sg::node::~node ( )
inlinevirtual

Definition at line 112 of file node.

112  {
113 #ifdef TOOLS_MEM
114  mem::decrement(s_class().c_str());
115 #endif
116  }

◆ node() [2/2]

tools::sg::node::node ( const node )
inlineprotected

Definition at line 118 of file node.

119  {
120 #ifdef TOOLS_MEM
121  mem::increment(s_class().c_str());
122 #endif
123  }

Member Function Documentation

◆ add_field()

void tools::sg::node::add_field ( field a_field)
inlineprotected

Definition at line 128 of file node.

128  {
129  m_fields.push_back(a_field); //it does not take ownerhship.
130  }

◆ bbox()

virtual void tools::sg::node::bbox ( bbox_action )
inlinevirtual

◆ cast()

virtual void* tools::sg::node::cast ( const std::string &  a_class) const
inlinevirtual

Reimplemented in tools::sg::tex_rect, tools::sg::tex_quadrilateral, tools::sg::holder< T >, and tools::sg::ellipse.

Definition at line 38 of file node.

38  {
39  if(void* p = cmp_cast<node>(this,a_class)) return p;
40  return 0;
41  }

◆ check_fields()

void tools::sg::node::check_fields ( std::ostream &  a_out) const
inlineprotected

Definition at line 296 of file node.

296  {
297  const std::vector<field_desc>& fds = node_desc_fields();
298  tools_vforcit(field*,m_fields,it) {
299  bool found = false;
300  tools_vforcit(field_desc,fds,itd) {
301  if( ((*itd).offset()==field_offset(*it)) &&
302  ((*itd).cls()==(*it)->s_cls())
303  ){
304  found = true;
305  break;
306  }
307  }
308  if(!found) {
309  a_out << "tools::sg::node::check_fields :"
310  << " WARNING : node of class " << s_cls()
311  << " has bad fields description."
312  << std::endl;
313  }
314  }
315  }

◆ cls_version()

virtual unsigned int tools::sg::node::cls_version ( ) const
inlinevirtual

Definition at line 46 of file node.

46 {return 1;}

◆ copy()

virtual node* tools::sg::node::copy ( ) const
pure virtual

Implemented in tools::sg::holder< T >.

◆ draw_in_frame_buffer()

virtual bool tools::sg::node::draw_in_frame_buffer ( ) const
inlinevirtual

Reimplemented in tools::sg::text_hershey_marker, tools::sg::text_freetype_marker, and tools::sg::markers.

Definition at line 94 of file node.

94 {return false;} // marker nodes return true.

◆ dump_field_descs()

void tools::sg::node::dump_field_descs ( std::ostream &  a_out) const
inline

Definition at line 253 of file node.

253  {
254  a_out << "field descs of node class " << s_cls() << " :" << std::endl;
255  const std::vector<field_desc>& fds = node_desc_fields();
256  tools_vforcit(field_desc,fds,itd) {
257  a_out << "name " << (*itd).name()
258  << ", class " << (*itd).cls()
259  << ", offset " << (*itd).offset()
260  << std::endl;
261  }
262  }

◆ event()

virtual void tools::sg::node::event ( event_action )
inlinevirtual

◆ field_from_desc()

field& tools::sg::node::field_from_desc ( const field_desc a_desc) const
inline

Definition at line 249 of file node.

249  {
250  //WARNING : touchy.
251  return *((field*)((char*)this+a_desc.offset()));
252  }

◆ field_offset()

field_desc::offset_t tools::sg::node::field_offset ( const field a_field) const
inlineprotected

Definition at line 278 of file node.

278  {
279  //WARNING : touchy.
280  return ((char*)(a_field)-(char*)(this));
281  }

◆ find_field()

field* tools::sg::node::find_field ( const field_desc a_rdesc) const
inlineprotected

Definition at line 283 of file node.

283  {
284  const std::vector<field_desc>& fds = node_desc_fields();
285  tools_vforcit(field_desc,fds,it) {
286  if((*it).name()==a_rdesc.name()) {
287  tools_vforcit(field*,m_fields,itf) {
288  //::printf("debug : find_field : look : %s\n",field_name(*(*it)).c_str());
289  if(field_offset(*itf)==(*it).offset()) return (*itf);
290  }
291  }
292  }
293  return 0;
294  }

◆ find_field_by_name()

field* tools::sg::node::find_field_by_name ( const std::string &  a_name) const
inline

Definition at line 263 of file node.

263  {
264  // a_name is of the form <class>.<field>. For example for color on sg::text, there are :
265  // tools::sg::back_area.color
266  // tools::sg::text.color
267  const std::vector<field_desc>& fds = node_desc_fields();
268  tools_vforcrit(field_desc,fds,it) {
269  if((*it).name()==a_name) {
270  tools_vforcit(field*,m_fields,itf) {
271  if(field_offset(*itf)==(*it).offset()) return (*itf);
272  }
273  }
274  }
275  return 0;
276  }

◆ get_matrix()

virtual void tools::sg::node::get_matrix ( get_matrix_action a_action)
inlinevirtual

Reimplemented in tools::sg::separator, tools::sg::noderef, tools::sg::matrix, tools::sg::group, and tools::sg::base_camera.

Definition at line 76 of file node.

76  {
77  if(this==a_action.node()){
78  a_action.set_found_model(a_action.model_matrix());
79  a_action.set_done(true);
80  }
81  }

◆ is_visible()

virtual void tools::sg::node::is_visible ( visible_action )
inlinevirtual

◆ node_desc_fields()

virtual const desc_fields& tools::sg::node::node_desc_fields ( ) const
inlinevirtual

◆ operator=()

node& tools::sg::node::operator= ( const node )
inlineprotected

Definition at line 124 of file node.

124  {
125  return *this;
126  }

◆ pick()

virtual void tools::sg::node::pick ( pick_action )
inlinevirtual

◆ protocol_one_fields()

virtual void tools::sg::node::protocol_one_fields ( std::vector< field * > &  a_fields) const
inlinevirtual

Reimplemented in tools::sg::atb_vertices.

Definition at line 92 of file node.

92 {a_fields = m_fields;}

◆ read()

virtual bool tools::sg::node::read ( read_action a_action)
inlinevirtual

Definition at line 89 of file node.

89 {return read_fields(a_action);}

◆ read_fields()

bool tools::sg::node::read_fields ( read_action a_action)
inlineprotected

Definition at line 153 of file node.

153  { //used in protocol-2.
154  node_desc rndesc;
155  if(!a_action.get_node_desc(s_cls(),rndesc)) {
156  a_action.out() << "tools::node::read_fields :"
157  << " for node class " << s_cls()
158  << " : read_action.get_node_desc() failed."
159  << std::endl;
160  return false;
161  }
162  //Whatever the current node fields, we must read all rndesc.fields() :
163  tools_vforcit(field_desc,rndesc.fields(),it) {
164  const field_desc& fdesc = *it;
165 
166  field* fd = find_field(fdesc);
167  if(!fd) {
168  a_action.out() << "tools::node::read_fields :"
169  << " for node class " << s_cls()
170  << " : field desc name " << fdesc.name()
171  << " : field desc class " << fdesc.cls()
172  << " : field desc offset " << fdesc.offset()
173  << " : field not found."
174  << "."
175  << std::endl;
176 //#define TOOLS_NODE_DEBUG_READ_FIELD
177 #ifdef TOOLS_NODE_DEBUG_READ_FIELD
178  check_fields(a_action.out()); //costly.
179  dump_field_descs(a_action.out());
180  {a_action.out() << "read field descs of node class " << s_cls() << " :" << std::endl;
181  tools_vforcit(field_desc,rndesc.fields(),itr) {
182  a_action.out() << "name " << (*itr).name()
183  << ", class " << (*itr).cls()
184  << ", offset " << (*itr).offset()
185  << std::endl;
186  }}
187  {a_action.out() << "m_fields of node class " << s_cls() << " :" << std::endl;
188  tools_vforcit(field*,m_fields,itm) {
189  a_action.out() << "field class " << (*itm)->s_cls()
190  << ", found offset " << field_offset(*itm)
191  << std::endl;
192  }}
193  ::exit(0);
194 #endif
195  fd = a_action.field_factory().create(fdesc.cls());
196  if(!fd) {
197  a_action.out() << "tools::node::read_fields :"
198  << " for node class " << s_cls()
199  << " : field desc class " << fdesc.cls()
200  << " : can't create generic field."
201  << "."
202  << std::endl;
203  return false;
204  }
205  } /*else {
206  a_action.out() << "debug : inlib::node::read_fields :"
207  << " for node class " << s_cls()
208  << " : field desc class " << fdesc.cls()
209  << " : field desc offset " << fdesc.offset()
210  << " : field found."
211  << "."
212  << std::endl;
213  }*/
214 
215  if(!fd->read(a_action.buffer())) {
216  a_action.out() << "tools::node::read_fields :"
217  << " for node class " << s_cls()
218  << " : and field class " << fd->s_cls()
219  << " : field read() failed."
220  << std::endl;
221  return false;
222  }
223  //fd->dump(a_action.out());
224  }
225 
226  //NOTE : if some current node fields had not been found
227  // in rndesc.fields(), they catch the default value
228  // of the node fields.
229 
230  return true;
231  }

◆ render()

virtual void tools::sg::node::render ( render_action )
inlinevirtual

◆ reset_touched()

virtual void tools::sg::node::reset_touched ( )
inlinevirtual

Reimplemented in tools::sg::plotter, and tools::sg::axis.

Definition at line 102 of file node.

102  {
103  tools_vforcit(field*,m_fields,it) (*it)->reset_touched();
104  }

◆ s_cls()

virtual const std::string& tools::sg::node::s_cls ( ) const
pure virtual

Implemented in tools::sg::holder< T >.

◆ search()

virtual void tools::sg::node::search ( search_action a_action)
inlinevirtual

Reimplemented in tools::sg::text_valop, tools::sg::text, tools::sg::plotter, tools::sg::plots, tools::sg::noderef, tools::sg::nodekit, tools::sg::legend, tools::sg::infos_box, tools::sg::group, tools::sg::back_area, tools::sg::axis, and tools::sg::_switch.

Definition at line 56 of file node.

56  {
57  if(a_action.what()==search_action::search_node_of_class) {
58  if(void* p = cast(a_action.sclass())) {
59  a_action.add_obj(p);
60  if(a_action.stop_at_first()) a_action.set_done(true);
61  }
62  } else if(a_action.what()==search_action::search_path_to_node) {
63  if(this==a_action.node()){
64  a_action.path_push(this); //ending node in the path.
65  a_action.set_done(true);
66  }
67  } else if(a_action.what()==search_action::search_path_to_node_of_class) {
68  if(cast(a_action.sclass())) {
69  search_action::path_t path = a_action.path();
70  path.push_back(this);
71  a_action.add_path(path);
72  if(a_action.stop_at_first()) a_action.set_done(true);
73  }
74  }
75  }

◆ touch()

void tools::sg::node::touch ( )
inline

Definition at line 233 of file node.

233  {
234  if(m_fields.empty()) return;
235  m_fields.front()->touch();
236  }

◆ touched()

virtual bool tools::sg::node::touched ( )
inlinevirtual

Reimplemented in tools::sg::plotter, tools::sg::plots, and tools::sg::axis.

Definition at line 96 of file node.

96  { //virtual for plotter.
97  tools_vforcit(field*,m_fields,it) {
98  if((*it)->touched()) return true;
99  }
100  return false;
101  }

◆ write()

virtual bool tools::sg::node::write ( write_action a_action)
inlinevirtual

Reimplemented in tools::sg::separator, tools::sg::plotter, tools::sg::plots, tools::sg::noderef, tools::sg::infos_box, tools::sg::group, tools::sg::axis, and tools::sg::_switch.

Definition at line 82 of file node.

82  {
83  if(!a_action.beg_node(*this)) return false;
84  if(!write_fields(a_action)) return false;
85  if(!a_action.end_node(*this)) return false;
86  return true;
87  }

◆ write_fields()

bool tools::sg::node::write_fields ( write_action a_action)
inlineprotected

Definition at line 132 of file node.

132  {
133 
134  check_fields(a_action.out()); //costly.
135  //dump_field_descs(a_action.out());
136 
137  unsigned int index = 0;
138  tools_vforcit(field*,m_fields,it) {
139  if(!(*it)->write(a_action.buffer())) {
140  a_action.out() << "node::write_fields :"
141  << " for field index " << index
142  << " and field class " << (*it)->s_cls()
143  << " of node class " << s_cls()
144  << " : field.write() failed" << "."
145  << std::endl;
146  return false;
147  }
148  index++;
149  }
150  return true;
151  }

The documentation for this class was generated from the following file:
tools::sg::node::check_fields
void check_fields(std::ostream &a_out) const
Definition: node:296
tools::sg::node::field_offset
field_desc::offset_t field_offset(const field *a_field) const
Definition: node:278
tools::sg::node::s_cls
virtual const std::string & s_cls() const =0
tools::sg::search_action::search_path_to_node
@ search_path_to_node
Definition: search_action:61
tools::sg::node::dump_field_descs
void dump_field_descs(std::ostream &a_out) const
Definition: node:253
tools::sg::search_action::search_node_of_class
@ search_node_of_class
Definition: search_action:60
tools::sg::node::cast
virtual void * cast(const std::string &a_class) const
Definition: node:38
tools_vforcrit
#define tools_vforcrit(a__T, a__v, a__it)
Definition: forit:16
tools::sg::search_action::search_path_to_node_of_class
@ search_path_to_node_of_class
Definition: search_action:62
tools::sg::search_action::path_t
std::vector< sg::node * > path_t
Definition: search_action:93
tools::sg::node::read_fields
bool read_fields(read_action &a_action)
Definition: node:153
tools::sg::node::node_desc_fields
virtual const desc_fields & node_desc_fields() const
Definition: node:48
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
tools::sg::node::write_fields
bool write_fields(write_action &a_action)
Definition: node:132
tools::sg::node::find_field
field * find_field(const field_desc &a_rdesc) const
Definition: node:283
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7