Rumba C++ SDK
Scene.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2018
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "Array.h"
18 #include "Dict.h"
19 #include "Shape.h"
20 
21  namespace maquina
22  {
24 
36  {
37  public:
38  SceneConst();
39  SceneConst(const Value &v);
40 
42  const std::string& name() const;
43 
45  const Imath::M44d& matrix() const;
46 
48  bool has_geometry() const;
49 
51 
53  bool has_attribute(const StringView& attribute) const;
54 
56 
59  const Value attribute(const StringView& attribute) const;
60 
62 
64  {
65  public:
68  {
69  public:
70  bool operator==(const Iterator &other) const;
71  bool operator!=(const Iterator &other) const;
72  Iterator& operator++();
73  Iterator(void *iterator);
74  Iterator(const Iterator& other);
75  ~Iterator();
76 
78  StringView name() const;
79  Value value() const;
80  private:
81  void *_internal;
82  };
83 
85  Attributes(std::shared_ptr<Impl> _value);
86 
87  Iterator begin() const;
88  Iterator end() const;
89 
91  size_t size() const;
92  private:
93  std::shared_ptr<Impl> _value;
94  };
95 
97  Attributes read_attributes() const;
98 
100  const Shape geometry() const;
101 
103  std::shared_ptr<SceneConst> child(
104  const std::string& path
105  ) const;
106 
108 
111  {
112  public:
115  {
116  public:
117  bool operator==(const Iterator &other) const;
118  bool operator!=(const Iterator &other) const;
119  Iterator& operator++();
120  Iterator(void *iterator);
121  Iterator(const Iterator& other);
122  ~Iterator();
123 
125  StringView name() const;
126  Value value() const;
127  private:
128  void *_internal;
129  };
130 
132  TraversalAttributes(void *internal_);
133  Iterator begin() const;
134  Iterator end() const;
135 
137  size_t size() const;
138  private:
139  void* _internal;
140  };
141 
143 
145  {
146  public:
149  public std::iterator<
150  std::forward_iterator_tag,
151  SceneConst, std::ptrdiff_t, SceneConst, SceneConst >
152  {
153  public:
154  reference operator*() const;
155  bool operator==(const Iterator &other) const;
156  bool operator!=(const Iterator &other) const;
157  Iterator& operator++();
158  Iterator(void *iterator);
159  Iterator( const Iterator &other );
160  ~Iterator();
161 
163  Imath::M44d world_matrix() const;
164 
166  bool visible() const;
167 
169  std::string path() const;
170 
172  bool has_attribute(const StringView& attribute) const;
173 
175 
178  Value attribute(const StringView& attribute) const;
179 
181 
182  TraversalAttributes attributes() const;
183 
184  private:
185  void *_internal;
186  };
187 
189  Traversal( const std::shared_ptr<Impl>& value, bool children_only, bool shapes_only )
190  : _value{ value }, _children_only(children_only), _shapes_only(shapes_only)
191  {}
192  Iterator begin() const;
193  Iterator end() const;
194 
196  size_t size() const;
197  private:
198  std::shared_ptr<Impl> _value;
199  bool _children_only;
200  bool _shapes_only;
201  };
202 
204  Traversal read_children(bool children_only = false, bool shapes_only = false) const;
205 
207  static const SceneConst default_value;
208 
210  SceneConst(std::shared_ptr<Impl> impl) { _impl=impl; }
211  };
212 
215  {
216  public:
217  Scene(const StringView& name = "", const gsl::span<SceneConst>& children = gsl::span<SceneConst>());
218 
220  void set_name(const char*);
221 
223  void set_matrix(const Imath::M44d&);
224 
226  void set_geometry(const Shape& geometry);
227 
229  void remove_geometry();
230 
232 
233  void set_attribute(const StringView& attribute, const Value& value);
234 
235  void merge(const SceneConst& other, const std::function<void(Scene& a, const SceneConst& b)>& func);
236 
238 
239  Scene add_child(
240  const std::string& path
241  );
242 
244  void add_child(const SceneConst& child);
245 
246  // Remove all children nodes which are empty
248  void prune_empty_nodes();
249 
251 
253  {
254  public:
257  public std::iterator<
258  std::forward_iterator_tag,
259  Scene, std::ptrdiff_t, Scene, Scene >
260  {
261  public:
262  reference operator*() const;
263  bool operator==(const Iterator &other) const;
264  bool operator!=(const Iterator &other) const;
265  Iterator& operator++();
266  Iterator(void *iterator);
267  Iterator(const Iterator &other);
268  Iterator(Iterator &&other);
269  Iterator& operator=(const Iterator& other);
270  Iterator& operator=(Iterator&& other);
271  ~Iterator();
272 
274  Imath::M44d world_matrix() const;
275 
277  bool visible() const;
278 
280 
281  std::string path() const;
282 
284  bool has_attribute(const StringView& attribute) const;
285 
287 
290  Value attribute(const StringView& attribute) const;
291 
293 
294  TraversalAttributes attributes() const;
295  private:
296  void *_internal;
297  };
298 
300  Traversal( const std::shared_ptr<Impl>& value, bool children_only, bool shapes_only )
301  : _value{ value }, _children_only(children_only), _shapes_only(shapes_only)
302  {}
303  Iterator begin() const;
304  Iterator end() const;
305 
307  size_t size() const;
308  private:
309  std::shared_ptr<Impl> _value;
310  bool _children_only;
311  bool _shapes_only;
312  };
313 
315  Traversal write_children(bool children_only = false, bool shapes_only = false);
316 
318  Scene(std::shared_ptr<Impl> impl) { _impl=impl; }
319  };
320 
321  MAQUINA_EXPORT Scene duplicate(const SceneConst& other);
322 
323  }
A Node children iterator.
Definition: Scene.h:148
MAQUINA_EXPORT Node reference(Node &root, const std::wstring &filepath, const std::string &reference_root_name="")
Reference the content of a file into the project.
Definition: ImathFrame.h:43
A Node children iterator.
Definition: Scene.h:114
A mutable scene node value.
Definition: Scene.h:214
Buffer< T > duplicate(const BufferConst< T > &a)
Definition: Buffer.h:161
A value with geometrical attributes. Base of all shape values.
Definition: Shape.h:26
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
A Node children iterator.
Definition: Scene.h:67
A Node children iterator.
Definition: Scene.h:256
A scene iterator.
Definition: Scene.h:252
#define MAQUINA_EXPORT
Definition: Export.h:31
A scene iterator.
Definition: Scene.h:144
static const SceneConst default_value
The default value.
Definition: Scene.h:207
An node&#39;s attribute iteration.
Definition: Scene.h:63
An attribute iteration on a traversal node.
Definition: Scene.h:110
An immutable scene node value.
Definition: Scene.h:35
bool operator!=(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:305
bool operator==(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:273
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
Base class of all Rumba values.
Definition: Value.h:34