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 <functional>
18 
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 
49  bool is_shown() const;
50 
52  bool is_selected() const;
53 
55  bool reset_matrix() const;
56 
58  bool has_geometry() const;
59 
61  const Shape geometry() const;
62 
64 
66  Imath::Box3d bounding_box() const;
67 
69 
71  bool has_attribute(const StringView& attribute) const;
72 
74 
77  const Value attribute(const StringView& attribute) const;
78 
80 
82  {
83  public:
86  {
87  public:
88  bool operator==(const Iterator &other) const;
89  bool operator!=(const Iterator &other) const;
90  Iterator& operator++();
91  Iterator(void *iterator);
92  Iterator(const Iterator& other);
93  ~Iterator();
94 
96  StringView name() const;
97  Value value() const;
98  private:
99  void *_internal;
100  };
101 
103  Attributes(std::shared_ptr<Impl> _value);
104 
105  Iterator begin() const;
106  Iterator end() const;
107 
109  size_t size() const;
110  private:
111  std::shared_ptr<Impl> _value;
112  };
113 
115  Attributes read_attributes() const;
116 
118 
120  std::shared_ptr<SceneConst> child(
121  const std::string& path,
122  Imath::M44d* world_matrix = nullptr
123  ) const;
124 
126 
179  std::pair<SceneConst, bool> filter(const std::function<std::pair<SceneConst, bool>(const SceneConst& scene, const StringView& path, const Imath::M44d* parent_world)>& filter_func,
180  const StringView& root_path = "", const Imath::M44d* root_world = nullptr) const;
181 
183 
186  {
187  public:
190  {
191  public:
192  bool operator==(const Iterator &other) const;
193  bool operator!=(const Iterator &other) const;
194  Iterator& operator++();
195  Iterator(void *iterator);
196  Iterator(const Iterator& other);
197  ~Iterator();
198 
200  StringView name() const;
201  Value value() const;
202  private:
203  void *_internal;
204  };
205 
207  TraversalAttributes(void *internal_);
208  Iterator begin() const;
209  Iterator end() const;
210 
212  size_t size() const;
213  private:
214  void* _internal;
215  };
216 
218 
220  {
221  public:
224  {
225  public:
226  using iterator_category = std::forward_iterator_tag;
228  using difference_type = std::ptrdiff_t;
231 
232  reference operator*() const;
233  bool operator==(const Iterator &other) const;
234  bool operator!=(const Iterator &other) const;
235  Iterator& operator++();
236  Iterator(void *iterator);
237  Iterator( const Iterator &other );
238  ~Iterator();
239 
241  Imath::M44d world_matrix() const;
242 
244  bool visible() const;
245 
247  std::string path() const;
248 
250  bool has_attribute(const StringView& attribute) const;
251 
253 
256  Value attribute(const StringView& attribute) const;
257 
259 
260  TraversalAttributes attributes() const;
261 
262  private:
263  void *_internal;
264  };
265 
267  Traversal( const std::shared_ptr<Impl>& value, bool children_only, bool shapes_only )
268  : _value{ value }, _children_only(children_only), _shapes_only(shapes_only)
269  {}
270  Iterator begin() const;
271  Iterator end() const;
272 
274  size_t size() const;
275  private:
276  std::shared_ptr<Impl> _value;
277  bool _children_only;
278  bool _shapes_only;
279  };
280 
282  Traversal read_children(bool children_only = false, bool shapes_only = false) const;
283 
285  static const SceneConst default_value;
286 
288  SceneConst(std::shared_ptr<Impl> impl) { _impl=impl; }
289  };
290 
293  {
294  public:
295  Scene(const StringView& name = "", const gsl::span<SceneConst>& children = gsl::span<SceneConst>());
296 
298  void set_name(const char*);
299 
301  void set_matrix(const Imath::M44d&);
302 
304  void set_shown(bool shown);
305 
307  void set_selected(bool selected);
308 
310  void set_reset_matrix(bool reset);
311 
313  void set_geometry(const Shape& geometry);
314 
316  void remove_geometry();
317 
319 
320  void set_attribute(const StringView& attribute, const Value& value);
321 
323  void remove_attribute(const StringView& attribute);
324 
325  void merge(const SceneConst& other, const std::function<void(Scene& a, const SceneConst& b)>& func);
326 
328 
329  Scene add_child(
330  const std::string& path
331  );
332 
334  void add_child(const SceneConst& child);
335 
337  void remove_child(const std::string& name);
338 
340  void clear_children();
341 
342  // Remove all children nodes which are empty
344  void prune_empty_nodes();
345 
347 
349  {
350  public:
353  {
354  public:
355  using iterator_category = std::forward_iterator_tag;
356  using value_type = Scene;
357  using difference_type = std::ptrdiff_t;
358  using pointer = Scene;
359  using reference = Scene;
360 
361  reference operator*() const;
362  bool operator==(const Iterator &other) const;
363  bool operator!=(const Iterator &other) const;
364  Iterator& operator++();
365  Iterator(void *iterator);
366  Iterator(const Iterator &other);
367  Iterator(Iterator &&other) noexcept;
368  Iterator& operator=(const Iterator& other);
369  Iterator& operator=(Iterator&& other) noexcept;
370  ~Iterator();
371 
373  Imath::M44d world_matrix() const;
374 
376  bool visible() const;
377 
379 
380  std::string path() const;
381 
383  bool has_attribute(const StringView& attribute) const;
384 
386 
389  Value attribute(const StringView& attribute) const;
390 
392 
393  TraversalAttributes attributes() const;
394  private:
395  void *_internal;
396  };
397 
399  Traversal( const std::shared_ptr<Impl>& value, bool children_only, bool shapes_only )
400  : _value{ value }, _children_only(children_only), _shapes_only(shapes_only)
401  {}
402  Iterator begin() const;
403  Iterator end() const;
404 
406  size_t size() const;
407  private:
408  std::shared_ptr<Impl> _value;
409  bool _children_only;
410  bool _shapes_only;
411  };
412 
414  Traversal write_children(bool children_only = false, bool shapes_only = false);
415 
417  Scene(std::shared_ptr<Impl> impl) { _impl=impl; }
418  };
419 
422  const SceneConst& scene,
423  bool recursive);
424 
425  }
Definition: ImathBox.h:71
A Node children iterator.
Definition: Scene.h:223
Definition: ImathFrame.h:43
A Node children iterator.
Definition: Scene.h:189
A mutable scene node value.
Definition: Scene.h:292
Buffer< T > duplicate(const BufferConst< T > &a)
Definition: Buffer.h:169
A value with geometrical attributes. Base of all shape values.
Definition: Shape.h:25
std::forward_iterator_tag iterator_category
Definition: Scene.h:226
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:85
std::forward_iterator_tag iterator_category
Definition: Scene.h:355
A Node children iterator.
Definition: Scene.h:352
A scene iterator.
Definition: Scene.h:348
#define MAQUINA_EXPORT
Definition: Export.h:31
A scene iterator.
Definition: Scene.h:219
static const SceneConst default_value
The default value.
Definition: Scene.h:285
An node&#39;s attribute iteration.
Definition: Scene.h:81
An attribute iteration on a traversal node.
Definition: Scene.h:185
An immutable scene node value.
Definition: Scene.h:35
bool operator!=(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:306
bool operator==(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:274
std::ptrdiff_t difference_type
Definition: Scene.h:357
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
std::ptrdiff_t difference_type
Definition: Scene.h:228
Base class of all Rumba values.
Definition: Value.h:34