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 "Impl.h"
18 #include "Macros.h"
19 
20 MAQUINA_IGNORE_WARNINGS_BEGIN
21 #include <ImathBox.h>
22 #include <ImathColor.h>
23 #include <ImathMatrix.h>
24 #include <ImathQuat.h>
25 MAQUINA_IGNORE_WARNINGS_END
26 
27 #include <vector>
28 #include <unordered_map>
29 #include "QueryContext.h"
30 
31  namespace maquina
32  {
33  class NodePlugin;
34  class NodeDelegate;
35  class Node;
36  class Value;
37  class ModificationContext;
38 
40 
53  {
54  public:
55  enum Flags
56  {
57  cache = 1 << 0,
58  time_varying = 1 << 1,
59  serial = 1 << 3,
60  hidden = 1 << 8,
61  channel = 1 << 9,
62  main = 1 << 12,
63  background = 1 << 30
64  };
65 
68  {
69  Automatic = -2
70  };
71 
73  Plug(
74  const char* name,
75  const Value& value,
76  uint32_t flags = 0
77  );
78 
80  // TODO use a const char* or a string_view here
81  std::string name() const;
82 
84  std::string document_path() const;
85 
87  std::string nice_name() const;
88 
90  std::string type_name() const;
91 
93  std::string description() const;
94 
96  void set_description( const std::string& description );
97 
99  void set_default_value(const Value& value);
100 
102  enum class EvaluationMode
103  {
104  Interactive = 0,
105  Exact = 1,
106  NoEvaluation = 2
107  };
108  static const int32_t AllFrames = int32_t(0x80000000);
109 
111 
112  Value default_value() const;
113 
117  void force_varying( bool force );
118 
120  Value value(
122  EvaluationMode mode=EvaluationMode::Interactive
123  ) const;
124 
126 
127  bool as_bool() const;
128 
130 
131  int as_int() const;
132 
134 
135  float as_float() const;
136 
138 
139  double as_double() const;
140 
142 
143  const std::string& as_string() const;
144 
145  // Returns the plug value as a wstring
146  std::wstring as_wstring() const;
147 
149 
150  const Imath::V2d& as_V2d() const;
151 
153 
154  const Imath::V3d& as_V3d() const;
155 
157 
158  const Imath::V4d& as_V4d() const;
159 
161 
162  const Imath::V2i& as_V2i() const;
163 
165 
166  const Imath::V3i& as_V3i() const;
167 
169 
170  const Imath::V4i& as_V4i() const;
171 
173 
174  const Imath::M44d &as_M44d() const;
175 
177 
178  const Imath::Box3f& as_Box3f() const;
179 
181 
182  const Imath::Color4f& as_Color4f() const;
183 
185 
186  const Imath::Quatd& as_Quatd() const;
187 
189 
190  std::shared_ptr<const class UserData> as_user_data() const;
191 
193  void set_value(const Value& value, bool undo_stack=false);
194 
196  void set_value(const Value& value, const ModificationContext& mc);
197 
199 
201  void set_value(const Value& value, const ModificationContext& mc, int32_t start, int32_t end);
202 
204 
206  bool can_connect(
207  const Plug& other
208  ) const;
209 
211  bool is_connected() const;
212 
214  bool is_internal() const;
215 
217  bool is_channel() const;
218 
220  void set_channel( bool channel );
221 
223  bool is_constant() const;
224 
226  bool is_evaluated() const;
227 
229  bool is_keyable() const;
230 
232  bool is_main_plug() const;
233 
235 
236  bool is_auto_connect() const;
237 
239 
240  bool is_dynamic() const;
241 
243  bool is_animable() const;
244 
246  bool is_mutable() const;
247 
249  enum class Status
250  {
251  Default,
252  Overridden,
253  Animated
254  };
255 
257 
260  Plug::Status status() const;
261 
263 
265  void connect(const Plug& src,
266  bool undo_stack=false,
267  bool serialize=false);
268 
269  void disconnect(
270  bool undo_stack=false);
271 
280  void add_valued_dependency( const Plug& dependence, int32_t index = -1,
281  int32_t time_offset = 0, bool undo_stack = false, bool serialize = false);
282 
290  void remove_valued_dependency( const Plug& dependence, bool undo_stack = true );
291 
297  void remove_valued_dependency( uint32_t index, bool undo_stack = true );
298 
301  void remove_all_valued_dependencies( bool undo_stack = true );
302 
303  std::vector<Plug> notification_dependencies();
304  void add_notification_dependency(const Plug& dependence,
305  bool serialize=false);
306  void remove_notification_dependency(const Plug& dependence,
307  bool notify=true);
308  void remove_all_notification_dependencies(bool notify=true);
309 
310  std::vector<Plug> back_dependencies();
311  size_t back_dependencies_count();
312 
314  std::vector<Plug> valued_dependencies();
315  uint32_t valued_dependencies_count();
316 
320  bool has_valued_dependency( const Plug& plug );
321 
322  // Invalidate a plug
323  void touch();
324 
330  void touch(int first_frame, int last_frame, bool rest);
331 
333  void set_to_default();
334 
336  uint32_t flags() const;
337 
339  void set_flags(uint32_t flags);
340 
342 
343  Plug input() const;
344 
346 
348  {
349  public:
351  public std::iterator<
352  std::forward_iterator_tag,
353  Plug, std::ptrdiff_t, Plug, Plug >
354  {
355  public:
356  reference operator*() const noexcept;
357  bool operator==(const Iterator &other) const noexcept;
358  bool operator!=(const Iterator &other) const noexcept;
359  Iterator& operator++() noexcept;
360  Iterator()=delete;
361  Iterator(void* ite);
362  Iterator(const Iterator &other);
363  Iterator(Iterator &&other);
364  Iterator& operator=(const Iterator &other)=delete;
365  Iterator& operator=(Iterator &&other)=delete;
366  ~Iterator();
367  private:
368  void* _internal;
369  };
370 
371  Outputs(void* plug) noexcept
372  : _plug{ plug }
373  {
374  }
375  Iterator begin();
376  Iterator end();
377  private:
378  void* _plug;
379  };
380 
382  Outputs outputs() const;
383 
385  std::vector<Plug> channels();
386 
387  bool has_node() const;
388  Node node() const;
389 
391 
393  std::vector<Plug> walk_down() const;
394 
396  static bool validate_name(const char* plug_name);
397 
398  bool operator==(const Plug& o) const { return _owner == o._owner && _plug == o._plug; }
399  bool operator!=(const Plug& o) const { return _owner != o._owner || _plug != o._plug; }
400 
402  std::shared_ptr<NodeDelegate> node_delegate() const;
403 
404  struct Key
405  {
406  bool selected;
407  };
408 
410  std::unordered_map<float, Key> key_frames() const;
412  std::unordered_map<float, Key> key_frames_in_layer(const Node& layer) const;
413 
415  std::shared_ptr<Impl> _owner;
416  void *_plug;
417 
419  Plug(const std::shared_ptr<Impl>& node, void *plug)
420  : _owner{ node }
421  , _plug{ plug }
422  {}
423  };
424  }
425 
426 # include <functional>
427 namespace std
428 {
429  template<>
430  struct hash<::maquina::Plug>
431  {
432  std::size_t operator()( const ::maquina::Plug& plug ) const noexcept
433  {
434  return reinterpret_cast<size_t>( plug._plug );
435  }
436  };
437 }
Outputs(void *plug) noexcept
Definition: Plug.h:371
Definition: ImathBox.h:71
Definition: Plug.h:404
Status
Status of the plug.
Definition: Plug.h:249
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.
DependencyFlags
Dependency flags to pass to add_value_dependency.
Definition: Plug.h:67
Definition: ImathFrame.h:42
Definition: ImathColor.h:120
Definition: ImathFrame.h:43
Definition: Plug.h:427
void * _plug
Definition: Plug.h:416
A Plug accessor to the outputs.
Definition: Plug.h:347
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
std::size_t operator()(const ::maquina::Plug &plug) const noexcept
Definition: Plug.h:432
bool selected
Definition: Plug.h:406
EvaluationMode
The value evaluation modes.
Definition: Plug.h:102
Definition: ImathQuat.h:71
#define MAQUINA_EXPORT
Definition: Export.h:31
A node plug.
Definition: Plug.h:52
bool operator!=(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:305
Flags
Definition: Plug.h:55
Definition: ImathVec.h:61
bool operator==(const C *str, const StringViewBase< C, STDS > &sv) noexcept
Definition: StringView.h:273
Definition: Plug.h:350
bool operator!=(const Plug &o) const
Definition: Plug.h:399
static const QueryContext at_current_frame
Query at the current frame.
Definition: QueryContext.h:32
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
bool operator==(const Plug &o) const
Definition: Plug.h:398
Definition: QueryContext.h:21
Base class of all Rumba nodes.
Definition: Node.h:36
Base class of all Rumba values.
Definition: Value.h:34