Rumba C++ SDK
Plug.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2019
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include "ChannelType.h"
18 #include "Impl.h"
19 #include "Macros.h"
20 #include "Ptr.h"
21 
22 MAQUINA_IGNORE_WARNINGS_BEGIN
23 #include <ImathBox.h>
24 #include <ImathColor.h>
25 #include <ImathMatrix.h>
26 #include <ImathQuat.h>
27 #include <gsl/span>
28 MAQUINA_IGNORE_WARNINGS_END
29 
30 #include <vector>
31 #include <unordered_map>
32 #include "AttributeDescriptor.h"
33 #include "QueryContext.h"
34 
35  namespace maquina
36  {
37  class Channel;
38  class NodePlugin;
39  class NodeDelegate;
40  class Node;
41  class Value;
42  class ModificationContext;
43  class PartialInvalidation;
44  using PartialInvalidationPtr = Ptr<const PartialInvalidation>;
45 
47 
60  {
61  public:
62  class Flags
63  {
64  public:
65  enum Enum
66  {
67  none = 0,
68  cache = 1 << 0,
69  time_varying = 1 << 1,
70  serial = 1 << 3,
72  hidden = 1 << 8,
73  channel = 1 << 9,
74  main = 1 << 12,
75  auto_connect = 1 << 13,
76  no_input = 1 << 15,
77  background = 1 << 30
78  };
79  };
80 
83  {
84  Automatic = -2
85  };
86 
88  Plug(
89  const char* name,
90  const Value& value,
91  uint32_t flags = 0
92  );
93 
95  // TODO use a const char* or a string_view here
96  std::string name() const;
97 
99  std::string full_name() const;
100 
102  std::string document_path() const;
103 
105  std::string nice_name() const;
106 
109  {
110  Default = 0,
111  Exact = 1,
112  Approximation = 2,
113  };
114 
116  std::string type_name(TypeEvaluationMode mode = TypeEvaluationMode::Default) const;
117 
119  std::shared_ptr<AttributeDescriptor> description() const;
120 
122  void set_description( const std::string& description, bool undo_stack=false);
123 
125  void set_default_value(const Value& value);
126 
128  enum class EvaluationMode
129  {
130  Interactive = 0,
131  Exact = 1,
132  NoEvaluation = 2,
133  Rest = 3
134  };
135  static const int32_t AllFrames = int32_t(0x80000000);
136 
138 
139  Value default_value() const;
140 
142 
143  Value rest_value() const;
144 
148  void force_varying( bool force );
149 
151  Value value(
153  EvaluationMode mode=EvaluationMode::Interactive
154  ) const;
155 
157 
158  bool as_bool() const;
159 
161 
162  int as_int() const;
163 
165 
166  float as_float() const;
167 
169 
170  double as_double() const;
171 
173 
174  const std::string& as_string() const;
175 
176  // Returns the plug value as a wstring
177  std::wstring as_wstring() const;
178 
180 
181  const Imath::V2d& as_V2d() const;
182 
184 
185  const Imath::V3d& as_V3d() const;
186 
188 
189  const Imath::V4d& as_V4d() const;
190 
192 
193  const Imath::V2i& as_V2i() const;
194 
196 
197  const Imath::V3i& as_V3i() const;
198 
200 
201  const Imath::V4i& as_V4i() const;
202 
204 
205  const Imath::M44d &as_M44d() const;
206 
208 
209  const Imath::Box3f& as_Box3f() const;
210 
212 
213  const Imath::Color4f& as_Color4f() const;
214 
216 
217  const Imath::Quatd& as_Quatd() const;
218 
220 
221  std::shared_ptr<const class UserData> as_user_data() const;
222 
224  void set_value(const Value& value, bool undo_stack=false);
225 
227  void set_value(const Value& value, const PartialInvalidationPtr pi, bool undo_stack = false);
228 
230  void set_value(const Value& value, const ModificationContext& mc);
231 
233 
235  void set_value(const Value& value, const ModificationContext& mc, int32_t start, int32_t end);
236 
238 
240  bool can_connect(
241  const Plug& other
242  ) const;
243 
245  bool depend_on(
246  const gsl::span<const Plug>& plugs
247  ) const;
248 
250  bool is_connected() const;
251 
253  bool is_connection_serialized() const;
254 
256  bool is_internal() const;
257 
259  bool is_channel() const;
260 
262  void set_channel( bool channel );
263 
265  bool is_constant() const;
266 
268  bool is_evaluated() const;
269 
271  bool is_output() const;
272 
274  bool is_keyable() const;
275 
277  bool is_main_plug() const;
278 
280 
281  bool is_auto_connect() const;
282 
284 
285  bool is_dynamic() const;
286 
288 
289  bool is_referenced_dynamic() const;
290 
292  bool is_animable() const;
293 
295  bool is_mutable() const;
296 
298  bool is_referenced_connection() const;
299 
301  enum class Status
302  {
303  Default,
304  Overridden,
305  Animated
306  };
307 
309 
312  Plug::Status status() const;
313 
315 
317  void connect(const Plug& src,
318  bool undo_stack=false,
319  bool serialize=false);
320 
322  void disconnect(bool undo_stack=false);
323 
325  void disconnect_outputs(bool undo_stack=false);
326 
335  void add_dynamic_valued_dependency( const Plug& dependence,
336  int32_t time_offset = 0, bool undo_stack = false, bool serialize = false);
337 
338  [[deprecated]]
339  void add_valued_dependency( const Plug& dependence, int32_t index = -1,
340  int32_t time_offset = 0, bool undo_stack = false, bool serialize = false);
341 
351  void remove_dynamic_valued_dependency( const Plug& dependence, bool undo_stack = true );
352 
353  [[deprecated]]
354  void remove_valued_dependency( const Plug& dependence, bool undo_stack = true );
355 
363  void remove_dynamic_valued_dependency( uint32_t index, bool undo_stack = true );
364 
365  [[deprecated]]
366  void remove_valued_dependency( uint32_t index, bool undo_stack = true );
367 
370  void remove_all_dynamic_valued_dependencies( bool undo_stack = true );
371 
372  [[deprecated]]
373  void remove_all_valued_dependencies( bool undo_stack = true );
374 
375  std::vector<Plug> notification_dependencies();
376  void add_notification_dependency(const Plug& dependence,
377  bool serialize=false);
378  void remove_notification_dependency(const Plug& dependence,
379  bool notify=true);
380  void remove_all_notification_dependencies(bool notify=true);
381 
382  std::vector<Plug> back_dependencies();
383  size_t back_dependencies_count();
384 
386  std::vector<Plug> valued_dependencies();
387 
390  Plug valued_dependence(int dep_index) const;
391 
393  uint32_t valued_dependencies_count() const;
394 
398  bool has_valued_dependency( const Plug& plug ) const;
399 
400  // Invalidate a plug
401  void touch();
402 
408  void touch(int first_frame, int last_frame, bool rest);
409 
411  void set_to_default();
412 
414  uint32_t flags() const;
415 
417  void set_flags(uint32_t flags);
418 
420 
421  Plug input() const;
422 
431  Plug input_origin() const;
432 
434 
436  {
437  public:
439  {
440  public:
441  using iterator_category = std::forward_iterator_tag;
442  using value_type = Plug;
443  using difference_type = std::ptrdiff_t;
444  using pointer = Plug;
445  using reference = Plug;
446 
447  reference operator*() const noexcept;
448  bool operator==(const Iterator &other) const noexcept;
449  bool operator!=(const Iterator &other) const noexcept;
450  Iterator& operator++() noexcept;
451  Iterator()=delete;
452  Iterator(void* ite);
453  Iterator(const Iterator &other);
454  Iterator(Iterator &&other) noexcept;
455  Iterator& operator=(const Iterator &other)=delete;
456  Iterator& operator=(Iterator &&other)=delete;
457  ~Iterator();
458  private:
459  void* _internal;
460  };
461 
462  Outputs(void* plug) noexcept
463  : _plug{ plug }
464  {
465  }
466  Iterator begin();
467  Iterator end();
468  private:
469  void* _plug;
470  };
471 
473  Outputs outputs() const;
474 
475  [[deprecated]]
476  std::vector<Plug> channel_plugs() const;
477 
479  std::vector<Channel> channels() const;
480 
482  std::shared_ptr<Channel> channel() const;
483 
485  std::shared_ptr<Channel> channel(ChannelType channel_type) const;
486 
487  bool has_node() const;
488  Node node() const;
489 
491 
493  std::vector<Plug> walk_down() const;
494 
496  static bool validate_name(const char* plug_name);
497 
498  bool operator==(const Plug& o) const { return _owner == o._owner && _plug == o._plug; }
499  bool operator!=(const Plug& o) const { return _owner != o._owner || _plug != o._plug; }
500 
502  std::shared_ptr<NodeDelegate> node_delegate() const;
503 
504  struct Key
505  {
506  bool selected;
507  };
508 
510  std::unordered_map<float, Key> key_frames() const;
512  std::unordered_map<float, Key> key_frames_in_layer(const Node& layer) const;
513 
515  std::shared_ptr<Impl> _owner;
516  void *_plug;
517 
519  Plug(const std::shared_ptr<Impl>& node, void *plug)
520  : _owner{ node }
521  , _plug{ plug }
522  {}
523  };
524  }
525 
526 # include <functional>
527 namespace std
528 {
529  template<>
530  struct hash<::maquina::Plug>
531  {
532  std::size_t operator()( const ::maquina::Plug& plug ) const noexcept
533  {
534  return reinterpret_cast<size_t>( plug._plug );
535  }
536  };
537 }
Definition: ImathBox.h:71
Definition: Plug.h:504
Status
Status of the plug.
Definition: Plug.h:301
DependencyFlags
Dependency flags to pass to add_value_dependency.
Definition: Plug.h:82
Definition: ImathFrame.h:42
Definition: ImathColor.h:120
Definition: ImathFrame.h:43
Definition: Plug.h:527
ChannelType
Predefined channel types.
Definition: ChannelType.h:23
void * _plug
Definition: Plug.h:516
A Plug accessor to the outputs.
Definition: Plug.h:435
Definition: ImathVec.h:63
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
Definition: ModificationContext.h:21
The channel exists but is not visible in the user interface.
std::size_t operator()(const ::maquina::Plug &plug) const noexcept
Definition: Plug.h:532
MAQUINA_EXPORT Value default_value(const maquina::StringView &type_name)
Return the default value of a type.
none
Definition: BrushID.h:29
std::forward_iterator_tag iterator_category
Definition: Plug.h:441
bool selected
Definition: Plug.h:506
EvaluationMode
The value evaluation modes.
Definition: Plug.h:128
Definition: Plug.h:62
Definition: ImathQuat.h:71
#define MAQUINA_EXPORT
Definition: Export.h:31
A node plug.
Definition: Plug.h:59
TypeEvaluationMode
The plug&#39;s type evaluation modes.
Definition: Plug.h:108
std::ptrdiff_t difference_type
Definition: Plug.h:443
Ptr< const PartialInvalidation > PartialInvalidationPtr
Definition: EvalContext.h:26
Definition: ImathVec.h:61
Enum
Definition: Plug.h:65
Definition: Plug.h:438
bool operator!=(const Plug &o) const
Definition: Plug.h:499
static const QueryContext at_current_frame
Query at the current frame.
Definition: QueryContext.h:36
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
bool operator==(const Plug &o) const
Definition: Plug.h:498
Definition: QueryContext.h:22
Base class of all Rumba nodes.
Definition: Node.h:37
Base class of all Rumba values.
Definition: Value.h:34