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 "UserData.h"
18 #include "ModificationContext.h"
19 #include "QueryContext.h"
20 #include "StringView.h"
21 #include "Value.h"
22 #include "Plug.h"
23 
24 #include <unordered_set>
25 #include <memory>
26 #include <ImathEuler.h>
27 
28 namespace maquina
29 {
30  class NodeDelegateRumba;
31 }
32 
33 template class MAQUINA_EXPORT std::weak_ptr< maquina::NodeDelegate >;
34 template class MAQUINA_EXPORT std::enable_shared_from_this< maquina::NodeDelegate >;
35 
36 namespace maquina
37 {
39 
68  class MAQUINA_EXPORT NodeDelegate : public UserData, public std::enable_shared_from_this< NodeDelegate >
69  {
70  public:
71 
73 
75  virtual std::shared_ptr<NodeDelegate> parent() = 0;
76 
78 
80  virtual maquina::StringView name() const = 0;
81 
83 
85  virtual std::string path() const = 0;
86 
88  virtual Imath::Box3d bounding_box() const;
89 
91  virtual bool is_node() const;
92 
94  virtual StringView ui_description() const;
95 
97 
99  virtual Node node() const;
100 
102 
104  virtual bool operator==(const NodeDelegate& o) const = 0;
105 
107 
109  virtual bool operator!=(const NodeDelegate& o) const = 0;
110 
112 
114  virtual std::shared_ptr<NodeDelegate> find(const StringView& path);
115 
120 
123  virtual int child_count() const;
124 
126 
127  virtual std::shared_ptr<NodeDelegate> child(const StringView& name);
128 
131  {
132  public:
134  virtual std::shared_ptr<NodeDelegate> operator*() const = 0;
135  virtual std::shared_ptr<NodeDelegate> operator->() const = 0;
136  virtual bool operator==(const ChildIteratorDelegate &other) const = 0;
137  virtual bool operator!=(const ChildIteratorDelegate &other) const = 0;
138  virtual ChildIteratorDelegate& operator++() = 0;
139  };
140 
143  {
144  public:
145  ChildIterator(const std::shared_ptr<ChildIteratorDelegate>& impl);
146  std::shared_ptr<NodeDelegate> operator*() const;
147  std::shared_ptr<NodeDelegate> operator->() const;
148  bool operator==(const ChildIterator &other) const;
149  bool operator!=(const ChildIterator &other) const;
150  ChildIterator& operator++();
151  private:
152  std::shared_ptr<ChildIteratorDelegate> _impl;
153  };
154 
155  protected:
156 
158  virtual std::shared_ptr<ChildIteratorDelegate> _children_begin();
160  virtual std::shared_ptr<ChildIteratorDelegate> _children_end();
161 
162  public:
163 
165  class Children
166  {
167  friend class NodeDelegate;
168  public:
170  Children(const std::shared_ptr<NodeDelegate>& node);
172  ChildIterator begin() const;
174  ChildIterator end() const;
175  private:
176  const std::shared_ptr<NodeDelegate> _node;
177  };
178  // end of Children
180 
185  class AttributeDelegate;
187 
190  class Observer
191  {
192  public:
193  virtual ~Observer() {};
195 
198  virtual std::shared_ptr<AttributeDelegate> attribute() = 0;
199  };
200 
203  {
204  public:
205  virtual ~AttributeDelegate() {}
207 
209  virtual std::shared_ptr<NodeDelegate> owner() = 0;
210 
212  virtual std::string name() const = 0;
213 
215 
217  virtual bool is_mutable() const;
218 
220 
222  virtual bool is_visible() const;
223 
225 
227  virtual bool is_animable() const;
228 
230 
232  virtual bool accepts_overrides() const;
233 
235 
237  virtual bool is_overridden() const;
238 
240 
242  virtual void add_override();
243 
245 
247  virtual void remove_override();
248 
250  virtual Value value() const = 0;
251 
253  virtual StringView type_name() const = 0;
254 
256  virtual bool is_plug() const;
257 
259 
261  virtual Plug plug() const;
262 
264  virtual std::string description() const;
265 
267 
268  virtual bool has_node_delegate() const;
269 
271 
273  virtual std::shared_ptr<NodeDelegate> node_delegate();
274 
276  virtual void set_value(const Value& value, const ModificationContext& mc=ModificationContext::undoable);
277 
279 
286  virtual std::shared_ptr<Observer> create_observer(const std::function<void()>& func, bool in_interactive=true);
287  };
288 
290  virtual int attribute_count() const;
291 
293 
294  virtual std::shared_ptr<AttributeDelegate> attribute(const StringView& name);
295 
297  virtual void channels( std::unordered_set<Plug>& set ) const;
298 
301  {
302  public:
304  virtual std::shared_ptr<AttributeDelegate> operator*() const = 0;
305  virtual std::shared_ptr<AttributeDelegate> operator->() const = 0;
306  virtual bool operator==(const AttributeIteratorDelegate &other) const = 0;
307  virtual bool operator!=(const AttributeIteratorDelegate &other) const = 0;
308  virtual AttributeIteratorDelegate& operator++() = 0;
309  };
310 
313  {
314  public:
315  AttributeIterator(const std::shared_ptr<AttributeIteratorDelegate>& impl);
316  std::shared_ptr<AttributeDelegate> operator*() const;
317  std::shared_ptr<AttributeDelegate> operator->() const;
318  bool operator==(const AttributeIterator &other) const;
319  bool operator!=(const AttributeIterator &other) const;
320  AttributeIterator& operator++();
321  private:
322  std::shared_ptr<AttributeIteratorDelegate> _impl;
323  };
324 
325  protected:
326 
328  virtual std::shared_ptr<AttributeIteratorDelegate> _attributes_begin();
330  virtual std::shared_ptr<AttributeIteratorDelegate> _attributes_end();
331 
332  public:
333 
335  struct Attributes {
336  Attributes( const std::shared_ptr<NodeDelegate>& node ) : node{ node }{}
337  AttributeIterator begin() const { return node->_attributes_begin(); }
338  AttributeIterator end() const { return node->_attributes_end(); }
339  std::shared_ptr<NodeDelegate> node;
340  };
341 
342  Attributes attributes() { return Attributes{shared_from_this()}; }
343  // end of Attributes
345 
350 
353  virtual bool has_transform() const;
354 
356  virtual Imath::M44d matrix(const QueryContext& qc=QueryContext::at_current_frame) const;
357 
359  virtual Imath::M44d world_matrix(const QueryContext& qc=QueryContext::at_current_frame) const;
360 
362  virtual Imath::M44d parent_world_matrix(const QueryContext& qc=QueryContext::at_current_frame) const;
363 
364  virtual Imath::V3d rotate_pivot(const QueryContext& qc=QueryContext::at_current_frame) const;
365  virtual Imath::V3d scale_pivot(const QueryContext& qc=QueryContext::at_current_frame) const;
366  virtual Imath::V3d joint_orient(const QueryContext& qc=QueryContext::at_current_frame) const;
367 
369  {
370  ScaleX = 0x001,
371  ScaleY = 0x002,
372  ScaleZ = 0x004,
373  Scale = ScaleX|ScaleY|ScaleZ,
374  RotateX = 0x008,
375  RotateY = 0x010,
376  RotateZ = 0x020,
377  Rotate = RotateX|RotateY|RotateZ,
378  TranslateX = 0x040,
379  TranslateY = 0x080,
380  TranslateZ = 0x100,
381  Translate = TranslateX|TranslateY|TranslateZ,
382  AllComponents = Scale|Rotate|Translate
383  };
384 
386 
387  virtual int mutable_flags() const;
388 
390  virtual void start_transform(const QueryContext& qc=QueryContext::at_current_frame);
391 
393  virtual Imath::V3d scale(const QueryContext& qc=QueryContext::at_current_frame) const;
394 
396 
397  virtual void set_scale(const Imath::V3d& scale, const ModificationContext& mc=ModificationContext::layer);
398 
400 
401  virtual Imath::V3d rotation(const QueryContext& qc=QueryContext::at_current_frame) const;
402 
404 
405  virtual Imath::Eulerd::Order rotate_order(const QueryContext& qc=QueryContext::at_current_frame) const;
406 
408 
409  virtual void set_rotation(const Imath::V3d& rotation, const ModificationContext& mc=ModificationContext::layer);
410 
412 
413  virtual Imath::V3d translation(const QueryContext& qc=QueryContext::at_current_frame) const;
414 
416 
417  virtual void set_translation(const Imath::V3d& translation, const ModificationContext& mc=ModificationContext::layer);
418 
420  static Imath::V3d extract_translation(const Imath::M44d& matrix, const Imath::V3d& scale_pivot, const Imath::V3d& rotate_pivot);
421 
422  virtual std::shared_ptr<Observer> create_transform_observer(const std::function<void()>& func, bool in_interactive=true);
423  // end of Transformation
425 
430  virtual bool is_camera() const;
432 
434  virtual bool is_orthographic(const QueryContext& qc=QueryContext::at_current_frame) const;
435 
437  virtual float orthographic_width(const QueryContext& qc=QueryContext::at_current_frame) const;
438 
440  virtual void set_orthographic_width(float width, const ModificationContext& mc);
441 
443  virtual float center_of_interest(const QueryContext& qc=QueryContext::at_current_frame) const;
444 
446  virtual void set_center_of_interest(float coi, const ModificationContext& mc);
447 
449  virtual float focal_length(const QueryContext& qc=QueryContext::at_current_frame) const;
450 
452  virtual void set_focal_length(float fl, const ModificationContext& mc);
453 
455  virtual float horizontal_aperture(const QueryContext& qc=QueryContext::at_current_frame) const;
456 
458  virtual void set_horizontal_aperture(float horizontal_aperture, const ModificationContext& mc);
459 
461  virtual float vertical_aperture(const QueryContext& qc=QueryContext::at_current_frame) const;
462 
464  virtual void set_vertical_aperture(float vertical_aperture, const ModificationContext& mc);
465 
467  virtual float near_clipping_plane(const QueryContext& qc=QueryContext::at_current_frame) const;
468 
470  virtual void set_near_clipping_plane(float near_clipping_plane, const ModificationContext& mc);
471 
473  virtual float far_clipping_plane(const QueryContext& qc=QueryContext::at_current_frame) const;
474 
476  virtual void set_far_clipping_plane(float far_clipping_plane, const ModificationContext& mc);
477  // end of Camera
479 
480 
481  };
482 
483  inline NodeDelegate::Children::Children(const std::shared_ptr<NodeDelegate>& node) : _node(node)
484  {}
485 
487  {
488  return _node->_children_begin();
489  }
490 
492  {
493  return _node->_children_end();
494  }
495 
496  inline NodeDelegate::ChildIterator::ChildIterator(const std::shared_ptr<ChildIteratorDelegate>& impl) : _impl(impl)
497  {}
498 
499  inline std::shared_ptr<NodeDelegate> NodeDelegate::ChildIterator::operator*() const
500  {
501  return **_impl;
502  }
503 
504  inline std::shared_ptr<NodeDelegate> NodeDelegate::ChildIterator::operator->() const
505  {
506  return (*_impl).operator->();
507  }
508 
510  {
511  // we can have nullptr in _impl
512  return (!_impl || !other._impl) ? _impl == other._impl : (*_impl).operator==(*other._impl);
513  }
514 
516  {
517  return (!_impl || !other._impl) ? _impl != other._impl : (*_impl).operator!=(*other._impl);
518  }
519 
521  {
522  ++(*_impl);
523  return *this;
524  }
525 
526  inline NodeDelegate::AttributeIterator::AttributeIterator(const std::shared_ptr<AttributeIteratorDelegate>& impl) : _impl(impl)
527  {}
528 
529  inline std::shared_ptr<NodeDelegate::AttributeDelegate> NodeDelegate::AttributeIterator::operator*() const
530  {
531  return **_impl;
532  }
533 
534  inline std::shared_ptr<NodeDelegate::AttributeDelegate> NodeDelegate::AttributeIterator::operator->() const
535  {
536  return (*_impl).operator->();
537  }
538 
540  {
541  // we can have nullptr in _impl
542  return (!_impl || !other._impl) ? _impl == other._impl : (*_impl).operator==(*other._impl);
543  }
544 
546  {
547  return (!_impl || !other._impl) ? _impl != other._impl : (*_impl).operator!=(*other._impl);
548  }
549 
551  {
552  ++(*_impl);
553  return *this;
554  }
555 
556 }
std::shared_ptr< AttributeDelegate > operator->() const
Definition: NodeDelegate.h:534
A node attributes iteration.
Definition: NodeDelegate.h:335
Definition: ImathBox.h:71
AttributeIterator(const std::shared_ptr< AttributeIteratorDelegate > &impl)
Definition: NodeDelegate.h:526
AttributeIterator begin() const
Definition: NodeDelegate.h:337
Order
Definition: ImathEuler.h:151
Definition: ImathFrame.h:42
AttributeIterator & operator++()
Definition: NodeDelegate.h:550
Definition: ImathFrame.h:43
A node attribute iterator delegate to implement a child iterator in the plugin.
Definition: NodeDelegate.h:130
ChildIterator end() const
Return the end iterator of the children.
Definition: NodeDelegate.h:491
std::shared_ptr< NodeDelegate > operator*() const
Definition: NodeDelegate.h:499
AttributeIterator end() const
Definition: NodeDelegate.h:338
Attributes attributes()
Definition: NodeDelegate.h:342
ChildIterator(const std::shared_ptr< ChildIteratorDelegate > &impl)
Definition: NodeDelegate.h:496
std::shared_ptr< NodeDelegate > operator->() const
Definition: NodeDelegate.h:504
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
virtual ~Observer()
Definition: NodeDelegate.h:193
Definition: ModificationContext.h:21
bool operator==(const ChildIterator &other) const
Definition: NodeDelegate.h:509
ChildIterator & operator++()
Definition: NodeDelegate.h:520
bool operator==(const AttributeIterator &other) const
Definition: NodeDelegate.h:539
ChildIterator begin() const
Return the begin iterator of the children.
Definition: NodeDelegate.h:486
bool operator!=(const AttributeIterator &other) const
Definition: NodeDelegate.h:545
An object to keep an observer alive.
Definition: NodeDelegate.h:190
#define MAQUINA_EXPORT
Definition: Export.h:31
A node attribute delegate.
Definition: NodeDelegate.h:202
std::shared_ptr< NodeDelegate > node
Definition: NodeDelegate.h:339
A node plug.
Definition: Plug.h:52
std::shared_ptr< AttributeDelegate > operator*() const
Definition: NodeDelegate.h:529
A node children iteration.
Definition: NodeDelegate.h:165
MutableFlags
Definition: NodeDelegate.h:368
bool operator!=(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:305
virtual ~AttributeIteratorDelegate()
Definition: NodeDelegate.h:303
bool operator==(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:273
bool operator!=(const ChildIterator &other) const
Definition: NodeDelegate.h:515
A node attribute iterator.
Definition: NodeDelegate.h:142
Definition: UserData.h:26
virtual ~ChildIteratorDelegate()
Definition: NodeDelegate.h:133
Attributes(const std::shared_ptr< NodeDelegate > &node)
Definition: NodeDelegate.h:336
This interface gives a high level access to the document structure.
Definition: NodeDelegate.h:68
A node attribute iterator.
Definition: NodeDelegate.h:312
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
Definition: QueryContext.h:21
friend class NodeDelegate
Definition: NodeDelegate.h:167
A node attribute iterator delegate to implement in the plugin.
Definition: NodeDelegate.h:300
virtual ~AttributeDelegate()
Definition: NodeDelegate.h:205
Base class of all Rumba nodes.
Definition: Node.h:36
Base class of all Rumba values.
Definition: Value.h:34