Bayeux  3.4.1
Core Foundation library for SuperNEMO
face_info.h
Go to the documentation of this file.
1 // \file geomtools/face_info.h
2 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2015-03-17
4  * Last modified: 2015-03-17
5  *
6  * License:
7  *
8  * Description:
9  *
10  * Face information: 2D surface and positioning
11  *
12  * History:
13  *
14  */
15 
16 #ifndef GEOMTOOLS_FACE_INFO_H
17 #define GEOMTOOLS_FACE_INFO_H 1
18 
19 // Standard library:
20 #include <vector>
21 
22 // Third party:
23 // - Boost:
24 #include <boost/cstdint.hpp>
25 // - Bayeux/datatools:
26 #include <datatools/handle.h>
27 #include <datatools/i_tree_dump.h>
28 
29 // This project:
30 #include <geomtools/placement.h>
32 #include <geomtools/i_shape_2d.h>
33 
34 namespace geomtools {
35 
39  {
40  public:
41 
43  face_info();
44 
46  ~face_info();
47 
49  bool is_valid() const;
50 
52  bool has_identifier() const;
53 
55  bool has_face() const;
56 
58  bool has_positioning() const;
59 
61  bool has_label() const;
62 
64  void set_face_ref(i_shape_2d *);
65 
67  void set_face(const face_handle_type &);
68 
70  template <class Shape2D>
71  Shape2D & add_face()
72  {
73  Shape2D * face_ptr = new Shape2D;
74  _face_.reset(face_ptr);
75  return *face_ptr;
76  }
77 
79  void reset_face();
80 
82  const i_shape_2d & get_face_ref() const;
83 
86 
88  void set_identifier(const face_identifier &);
89 
91  const face_identifier & get_identifier() const;
92 
95 
97  void reset_identifier();
98 
100  const placement & get_positioning() const;
101 
104 
107 
109  void reset_positioning();
110 
112  const std::string & get_label() const;
113 
115  void set_label(const std::string &);
116 
118  void reset_label();
119 
121  template <class Shape2D>
122  bool is_a() const
123  {
124  // std::cerr << "DEVEL: face_info::is_a<>: " << "BEGIN" << std::endl;
125  try {
126  dynamic_cast<const Shape2D &>(_face_.get());
127  return true;
128  }
129  catch (...) {
130  }
131  // std::cerr << "DEVEL: face_info::is_a<>: " << "END" << std::endl;
132  return false;
133  }
134 
136  template <class Shape2D>
137  const Shape2D & get_face() const
138  {
139  return dynamic_cast<const Shape2D &>(_face_.get());
140  }
141 
143  template <class Shape2D>
144  Shape2D & grab_face()
145  {
146  return dynamic_cast<Shape2D &>(_face_.grab());
147  }
148 
150  void reset();
151 
153  virtual void tree_dump(std::ostream & out_ = std::clog,
154  const std::string & title_ = "",
155  const std::string & indent_ = "",
156  bool inherit_ = false) const;
157 
158  private:
159 
160  face_identifier _identifier_;
161  face_handle_type _face_;
162  placement _positioning_;
163  std::string _label_;
164 
165  };
166 
168  typedef std::vector<face_info> face_info_collection_type;
169 
172  std::ostream & out_,
173  const std::string & title_ = "",
174  const std::string & indent_ = "");
175 
176 
177 } // end of namespace geomtools
178 
179 #endif // GEOMTOOLS_FACE_INFO_H
180 
181 /*
182 ** Local Variables: --
183 ** mode: c++ --
184 ** c-file-style: "gnu" --
185 ** tab-width: 2 --
186 ** End: --
187 */
bool has_identifier() const
Check if a face identifier is available.
bool is_a() const
Check the explicit type of the face.
Definition: face_info.h:122
Shape2D & grab_face()
Return a the explicitely typed face (mutable)
Definition: face_info.h:144
void set_face_ref(i_shape_2d *)
Set the 2D face handle.
const i_shape_2d & get_face_ref() const
Return the face.
bool has_label() const
Check if a label is available.
void reset()
Reset.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
Identifier of a face attached to a solid shape.
Definition: face_identifier.h:32
void print_face_infos(const face_info_collection_type &, std::ostream &out_, const std::string &title_="", const std::string &indent_="")
Smart print.
const placement & get_positioning() const
Return the face positioning.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
bool has_positioning() const
Check if a positioning is available.
face_info()
Default constructor.
void reset_face()
Reset the face.
void set_identifier(const face_identifier &)
Set the face identifier.
const T & get() const
Definition: handle.h:214
const std::string & get_label() const
Return the face label.
Templatized handle class that wraps a Boost shared pointer and behaves like a reference.
Definition: handle.h:114
bool has_face() const
Check if a face is available.
void reset_positioning()
Reset face positioning.
Shape2D & add_face()
Set the 2D face with explicit type.
Definition: face_info.h:71
placement & grab_positioning()
Return the face positioning (mutable)
std::enable_if< std::is_same< Q, T >::value &&!std::is_const< Q >::value &&!std::is_const< T >::value, Q & >::type grab()
Definition: handle.h:234
The abstract base class for all 2D shapes/surfaces.
Definition: i_shape_2d.h:37
void reset(T *elem_=nullptr)
Reset the internal shared pointer with a new instance.
Definition: handle.h:274
void reset_identifier()
Reset the face identifier.
face_identifier & grab_identifier()
Return the face identifier (mutable)
i_shape_2d & grab_face_ref()
Return the face (mutable)
const Shape2D & get_face() const
Return a the explicitely typed face.
Definition: face_info.h:137
void set_face(const face_handle_type &)
Set the 2D face handle.
void set_identity_positioning()
Force face positioning to identity.
The placement for a geometry volume with its translation and rotation with respect to some mother ref...
Definition: placement.h:34
void reset_label()
Reset face label.
const face_identifier & get_identifier() const
Return the face identifier.
Information about the nature and positioning of a face of the solid.
Definition: face_info.h:38
void set_label(const std::string &)
Set face label.
bool is_valid() const
Check the validity.
std::vector< face_info > face_info_collection_type
Type alias for a collection of face information objects.
Definition: face_info.h:168
~face_info()
Destructor.
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39