Rumba C++ SDK
NodeDelegate.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2020
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "Buffer.h"
18 #include "UserData.h"
19 #include "ModificationContext.h"
20 #include "QueryContext.h"
21 #include "StringView.h"
22 #include "Value.h"
23 #include "Plug.h"
24 #include "SparseBuffer.h"
25 
26 #include <unordered_set>
27 #include <memory>
28 #include <ImathEuler.h>
29 
30 namespace maquina
31 {
32  class Channel;
33  class NodeDelegateRumba;
34  class Shape;
35 }
36 
37 template class MAQUINA_EXPORT std::weak_ptr< maquina::NodeDelegate >;
38 template class MAQUINA_EXPORT std::enable_shared_from_this< maquina::NodeDelegate >;
39 
40 namespace maquina
41 {
43 
72  class MAQUINA_EXPORT NodeDelegate : public std::enable_shared_from_this< NodeDelegate >
73  {
74  // *** Please update NodeDelegateWrapper after modifying NodeDelegate
75  friend class NodeDelegateWrapper;
76  public:
77  virtual ~NodeDelegate() {};
78 
79  virtual StringView type_name() const = 0;
80 
82 
84  virtual std::shared_ptr<NodeDelegate> parent() const = 0;
85 
87 
89  virtual maquina::StringView name() const = 0;
90 
92 
94  virtual std::string path() const = 0;
95 
97  virtual std::string document_path() const;
98 
100  virtual Imath::Box3d bounding_box() const;
101 
103  virtual bool is_node() const;
104 
106  virtual std::shared_ptr<class AttributeDescriptor> description() const;
107 
109 
111  virtual Node node() const;
112 
114 
116  virtual bool operator==(const NodeDelegate& o) const = 0;
117 
119 
121  virtual bool operator!=(const NodeDelegate& o) const = 0;
122 
124 
126  virtual std::shared_ptr<NodeDelegate> find(const StringView& path);
127 
132 
135  virtual int child_count() const;
136 
138 
139  virtual std::shared_ptr<NodeDelegate> child(const StringView& name);
140 
143  {
144  public:
146  virtual std::shared_ptr<NodeDelegate> operator*() const = 0;
147  virtual std::shared_ptr<NodeDelegate> operator->() const = 0;
148  virtual bool operator==(const ChildIteratorDelegate &other) const = 0;
149  virtual bool operator!=(const ChildIteratorDelegate &other) const = 0;
150  virtual ChildIteratorDelegate& operator++() = 0;
151  };
152 
155  {
156  public:
157  ChildIterator(const std::shared_ptr<ChildIteratorDelegate>& impl);
158  std::shared_ptr<NodeDelegate> operator*() const;
159  std::shared_ptr<NodeDelegate> operator->() const;
160  bool operator==(const ChildIterator &other) const;
161  bool operator!=(const ChildIterator &other) const;
162  ChildIterator& operator++();
163  private:
164  std::shared_ptr<ChildIteratorDelegate> _impl;
165  };
166 
167  protected:
168 
170  virtual std::shared_ptr<ChildIteratorDelegate> _children_begin();
172  virtual std::shared_ptr<ChildIteratorDelegate> _children_end();
173 
174  public:
175 
177  class Children
178  {
179  friend class NodeDelegate;
180  public:
182  Children(const std::shared_ptr<NodeDelegate>& node);
184  ChildIterator begin() const;
186  ChildIterator end() const;
187  private:
188  const std::shared_ptr<NodeDelegate> _node;
189  };
190 
191  Children children();
192  // end of Children
194 
199  class AttributeDelegate;
201 
204  class Observer
205  {
206  public:
207  virtual ~Observer() {};
209 
212  virtual std::shared_ptr<AttributeDelegate> attribute() = 0;
213  };
214 
217  {
218  public:
219  virtual ~AttributeDelegate() {}
221 
223  virtual std::shared_ptr<NodeDelegate> owner() = 0;
224 
226  virtual std::string name() const = 0;
227 
229 
231  virtual bool is_mutable() const;
232 
234 
236  virtual bool is_visible() const;
237 
239 
241  virtual bool is_animable() const;
242 
244 
246  virtual bool accepts_overrides() const;
247 
249 
251  virtual bool is_overridden() const;
252 
254 
256  virtual void add_override();
257 
259 
261  virtual void remove_override();
262 
264  virtual Value value(const QueryContext& qc=QueryContext::at_current_frame) const = 0;
265 
267  virtual StringView type_name() const = 0;
268 
270  virtual bool is_plug() const;
271 
273 
275  virtual Plug plug() const;
276 
278  virtual std::shared_ptr<AttributeDescriptor> description() const;
279 
281 
282  virtual bool has_node_delegate() const;
283 
285 
287  virtual std::shared_ptr<NodeDelegate> node_delegate();
288 
290  virtual void set_value(const Value& value, const ModificationContext& mc=ModificationContext::undoable);
291 
293 
300  virtual std::shared_ptr<Observer> create_observer(const std::function<void()>& func, bool in_interactive=true);
301 
302  // TODO optional
304  virtual std::shared_ptr<Channel> channel();
305 
306  // TODO optional
308  virtual std::shared_ptr<Channel> channel(const ChannelType sc);
309 
311  virtual std::vector<Channel> channels();
312  };
313 
315  virtual int attribute_count() const;
316 
318 
319  virtual std::shared_ptr<AttributeDelegate> attribute(const StringView& name);
320 
322 
325  virtual bool add_attribute(const StringView& name, const Value& value);
326 
328  // TODO optional
330  virtual std::shared_ptr<Channel> channel(const ChannelType sc);
331 
333  virtual std::vector<Channel> channels();
334 
335  [[deprecated]]
336  virtual void channel_plugs( std::unordered_set<Plug>& set ) const;
337 
346  virtual void animate();
347 
350  {
351  public:
353  virtual std::shared_ptr<AttributeDelegate> operator*() const = 0;
354  virtual std::shared_ptr<AttributeDelegate> operator->() const = 0;
355  virtual bool operator==(const AttributeIteratorDelegate &other) const = 0;
356  virtual bool operator!=(const AttributeIteratorDelegate &other) const = 0;
357  virtual AttributeIteratorDelegate& operator++() = 0;
358  };
359 
362  {
363  public:
364  AttributeIterator(const std::shared_ptr<AttributeIteratorDelegate>& impl);
365  std::shared_ptr<AttributeDelegate> operator*() const;
366  std::shared_ptr<AttributeDelegate> operator->() const;
367  bool operator==(const AttributeIterator &other) const;
368  bool operator!=(const AttributeIterator &other) const;
369  AttributeIterator& operator++();
370  private:
371  std::shared_ptr<AttributeIteratorDelegate> _impl;
372  };
373 
374  protected:
375 
377  virtual std::shared_ptr<AttributeIteratorDelegate> _attributes_begin();
379  virtual std::shared_ptr<AttributeIteratorDelegate> _attributes_end();
380 
381  public:
382 
384  struct Attributes {
385  Attributes( const std::shared_ptr<NodeDelegate>& node ) : node{ node }{}
386  AttributeIterator begin() const { return node->_attributes_begin(); }
387  AttributeIterator end() const { return node->_attributes_end(); }
388  std::shared_ptr<NodeDelegate> node;
389  };
390 
391  Attributes attributes() { return Attributes{shared_from_this()}; }
392  // end of Attributes
394 
399 
402  virtual bool has_transform() const;
403 
405  virtual Imath::M44d matrix(const QueryContext& qc=QueryContext::at_current_frame) const;
406 
408  virtual Imath::M44d world_matrix(const QueryContext& qc=QueryContext::at_current_frame) const;
409 
411  virtual Imath::M44d parent_world_matrix(const QueryContext& qc=QueryContext::at_current_frame) const;
412 
413  virtual Imath::V3d rotate_pivot(const QueryContext& qc=QueryContext::at_current_frame) const;
414  virtual Imath::V3d scale_pivot(const QueryContext& qc=QueryContext::at_current_frame) const;
415  virtual Imath::V3d joint_orient(const QueryContext& qc=QueryContext::at_current_frame) const;
416  virtual Imath::V3d rotate_axis(const QueryContext& qc=QueryContext::at_current_frame) const;
417 
419  {
420  ScaleX = 0x001,
421  ScaleY = 0x002,
422  ScaleZ = 0x004,
423  Scale = ScaleX|ScaleY|ScaleZ,
424  RotateX = 0x008,
425  RotateY = 0x010,
426  RotateZ = 0x020,
427  Rotate = RotateX|RotateY|RotateZ,
428  TranslateX = 0x040,
429  TranslateY = 0x080,
430  TranslateZ = 0x100,
431  Translate = TranslateX|TranslateY|TranslateZ,
432  AllComponents = Scale|Rotate|Translate
433  };
434 
436 
437  virtual int mutable_flags() const;
438 
441  {
442  public:
443  virtual ~TransformUserData() {}
444  };
445 
447 
449  virtual std::unique_ptr<TransformUserData> start_transform(const QueryContext& qc=QueryContext::at_current_frame);
450 
452 
453  virtual void end_transform(const ModificationContext& mc=ModificationContext::default_mc(), TransformUserData* user_data = nullptr);
454 
456 
457  virtual void set_matrix(const Imath::M44d& matrix, const ModificationContext& mc = ModificationContext::default_mc(), TransformUserData* user_data = nullptr);
458 
460  virtual Imath::V3d scale(const QueryContext& qc=QueryContext::at_current_frame) const;
461 
463 
464  virtual void set_scale(const Imath::V3d& scale, const ModificationContext& mc=ModificationContext::default_mc(), TransformUserData* user_data = nullptr);
465 
467 
468  virtual Imath::V3d rotation(const QueryContext& qc=QueryContext::at_current_frame) const;
469 
471 
472  virtual Imath::Eulerd::Order rotate_order(const QueryContext& qc=QueryContext::at_current_frame) const;
473 
475 
476  virtual void set_rotation(const Imath::V3d& rotation, const ModificationContext& mc=ModificationContext::default_mc(), TransformUserData* user_data = nullptr);
477 
479 
480  virtual Imath::V3d translation(const QueryContext& qc=QueryContext::at_current_frame) const;
481 
483 
484  virtual void set_translation(const Imath::V3d& translation, const ModificationContext& mc=ModificationContext::default_mc(), TransformUserData* user_data = nullptr);
485 
487  Imath::V3d extract_translation(const Imath::M44d& local_matrix, const QueryContext& mc=QueryContext::at_current_frame) const;
488 
490  Imath::V3d extract_rotation(Imath::M44d local_matrix, const QueryContext& mc=QueryContext::at_current_frame) const;
491 
493  virtual std::shared_ptr<Observer> create_transform_observer(const std::function<void()>& func, bool in_interactive=true);
494  // end of Transformation
496 
501  virtual bool is_camera() const;
503 
505  virtual bool is_locked() const;
506 
508  virtual void set_locked(bool locked, const ModificationContext& mc=ModificationContext::default_mc());
509 
511  virtual bool is_orthographic(const QueryContext& qc=QueryContext::at_current_frame) const;
512 
514  virtual float orthographic_width(const QueryContext& qc=QueryContext::at_current_frame) const;
515 
517  virtual void set_orthographic_width(float width, const ModificationContext& mc=ModificationContext::default_mc());
518 
520  virtual float center_of_interest(const QueryContext& qc=QueryContext::at_current_frame) const;
521 
523  virtual void set_center_of_interest(float coi, const ModificationContext& mc=ModificationContext::default_mc());
524 
526  virtual float near_clipping_plane(const QueryContext& qc=QueryContext::at_current_frame) const;
527 
529  virtual void set_near_clipping_plane(float near_clipping_plane, const ModificationContext& mc=ModificationContext::default_mc());
530 
532  virtual float far_clipping_plane(const QueryContext& qc=QueryContext::at_current_frame) const;
533 
535  virtual void set_far_clipping_plane(float far_clipping_plane, const ModificationContext& mc=ModificationContext::default_mc());
536 
538  virtual Imath::M44d projection_matrix(const QueryContext& qc=QueryContext::at_current_frame) const;
539 
541  virtual float aspect_ratio() const;
542 
544  virtual std::shared_ptr<NodeDelegate> aim() const;
545 
547  virtual std::shared_ptr<NodeDelegate> up() const;
548 
550  virtual std::shared_ptr<Observer> create_camera_observer(const std::function<void()>& func, bool in_interactive=true);
551  // end of Camera
553 
558  virtual bool has_geometry() const;
560 
562 
563  virtual Shape geometry() const;
564  // end of Geometry
566 
571  virtual bool is_sculpt() const;
573 
575  virtual BufferConstV3f input_points(const StringView& path, const QueryContext& qc=QueryContext::at_current_frame) const;
576 
578  virtual SparseBufferConstV3f delta_points(const StringView& path, const QueryContext& qc=QueryContext::at_current_frame) const;
579 
581  virtual void set_delta_points(const SparseBufferConstV3f& delta_points, const StringView& path, const ModificationContext& mc=ModificationContext::default_mc()) const;
582 
584  virtual std::shared_ptr<maquina::NodeDelegate::Observer> create_sculpt_observer(const std::function<void()>& func, bool in_interactive);
585  // end of Sculpt
587  };
588 
589  inline NodeDelegate::Children::Children(const std::shared_ptr<NodeDelegate>& node) : _node(node)
590  {}
591 
593  {
594  return _node->_children_begin();
595  }
596 
598  {
599  return _node->_children_end();
600  }
601 
602  inline NodeDelegate::ChildIterator::ChildIterator(const std::shared_ptr<ChildIteratorDelegate>& impl) : _impl(impl)
603  {}
604 
605  inline std::shared_ptr<NodeDelegate> NodeDelegate::ChildIterator::operator*() const
606  {
607  return **_impl;
608  }
609 
610  inline std::shared_ptr<NodeDelegate> NodeDelegate::ChildIterator::operator->() const
611  {
612  return (*_impl).operator->();
613  }
614 
616  {
617  // we can have nullptr in _impl
618  return (!_impl || !other._impl) ? _impl == other._impl : (*_impl).operator==(*other._impl);
619  }
620 
622  {
623  return (!_impl || !other._impl) ? _impl != other._impl : (*_impl).operator!=(*other._impl);
624  }
625 
627  {
628  ++(*_impl);
629  return *this;
630  }
631 
632  inline NodeDelegate::AttributeIterator::AttributeIterator(const std::shared_ptr<AttributeIteratorDelegate>& impl) : _impl(impl)
633  {}
634 
635  inline std::shared_ptr<NodeDelegate::AttributeDelegate> NodeDelegate::AttributeIterator::operator*() const
636  {
637  return **_impl;
638  }
639 
640  inline std::shared_ptr<NodeDelegate::AttributeDelegate> NodeDelegate::AttributeIterator::operator->() const
641  {
642  return (*_impl).operator->();
643  }
644 
646  {
647  // we can have nullptr in _impl
648  return (!_impl || !other._impl) ? _impl == other._impl : (*_impl).operator==(*other._impl);
649  }
650 
652  {
653  return (!_impl || !other._impl) ? _impl != other._impl : (*_impl).operator!=(*other._impl);
654  }
655 
657  {
658  ++(*_impl);
659  return *this;
660  }
661 
662 }
virtual ~TransformUserData()
Definition: NodeDelegate.h:443
std::shared_ptr< AttributeDelegate > operator->() const
Definition: NodeDelegate.h:640
A node attributes iteration.
Definition: NodeDelegate.h:384
Definition: ImathBox.h:71
AttributeIterator(const std::shared_ptr< AttributeIteratorDelegate > &impl)
Definition: NodeDelegate.h:632
AttributeIterator begin() const
Definition: NodeDelegate.h:386
Order
Definition: ImathEuler.h:151
Definition: ImathFrame.h:42
AttributeIterator & operator++()
Definition: NodeDelegate.h:656
Definition: ImathFrame.h:43
A blind data provided by the start_transform&#39;s implementation and passed to set_scale, set_rotation and set_translation.
Definition: NodeDelegate.h:440
ChannelType
Predefined channel types.
Definition: ChannelType.h:23
A node attribute iterator delegate to implement a child iterator in the plugin.
Definition: NodeDelegate.h:142
ChildIterator end() const
Return the end iterator of the children.
Definition: NodeDelegate.h:597
std::shared_ptr< NodeDelegate > operator*() const
Definition: NodeDelegate.h:605
AttributeIterator end() const
Definition: NodeDelegate.h:387
Attributes attributes()
Definition: NodeDelegate.h:391
ChildIterator(const std::shared_ptr< ChildIteratorDelegate > &impl)
Definition: NodeDelegate.h:602
A value with geometrical attributes. Base of all shape values.
Definition: Shape.h:25
std::shared_ptr< NodeDelegate > operator->() const
Definition: NodeDelegate.h:610
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
virtual ~Observer()
Definition: NodeDelegate.h:207
Definition: ModificationContext.h:21
virtual ~NodeDelegate()
Definition: NodeDelegate.h:77
bool operator==(const ChildIterator &other) const
Definition: NodeDelegate.h:615
ChildIterator & operator++()
Definition: NodeDelegate.h:626
bool operator==(const AttributeIterator &other) const
Definition: NodeDelegate.h:645
ChildIterator begin() const
Return the begin iterator of the children.
Definition: NodeDelegate.h:592
bool operator!=(const AttributeIterator &other) const
Definition: NodeDelegate.h:651
An object to keep an observer alive.
Definition: NodeDelegate.h:204
#define MAQUINA_EXPORT
Definition: Export.h:31
A node attribute delegate.
Definition: NodeDelegate.h:216
std::shared_ptr< NodeDelegate > node
Definition: NodeDelegate.h:388
A node plug.
Definition: Plug.h:59
std::shared_ptr< AttributeDelegate > operator*() const
Definition: NodeDelegate.h:635
A node children iteration.
Definition: NodeDelegate.h:177
MutableFlags
Definition: NodeDelegate.h:418
bool operator!=(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:306
virtual ~AttributeIteratorDelegate()
Definition: NodeDelegate.h:352
bool operator==(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:274
bool operator!=(const ChildIterator &other) const
Definition: NodeDelegate.h:621
A node attribute iterator.
Definition: NodeDelegate.h:154
virtual ~ChildIteratorDelegate()
Definition: NodeDelegate.h:145
Attributes(const std::shared_ptr< NodeDelegate > &node)
Definition: NodeDelegate.h:385
This interface gives a high level access to the document structure.
Definition: NodeDelegate.h:72
A node attribute iterator.
Definition: NodeDelegate.h:361
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
friend class NodeDelegateWrapper
Definition: NodeDelegate.h:75
Definition: QueryContext.h:22
friend class NodeDelegate
Definition: NodeDelegate.h:179
A node attribute iterator delegate to implement in the plugin.
Definition: NodeDelegate.h:349
virtual ~AttributeDelegate()
Definition: NodeDelegate.h:219
Base class of all Rumba nodes.
Definition: Node.h:37
Base class of all Rumba values.
Definition: Value.h:34