Rumba C++ SDK
Workspace.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 "Node.h"
18 #include <unordered_map>
19 #include <unordered_set>
20 #include <gsl/gsl>
21 
24  namespace maquina
25  {
26  class Array;
27  class Dict;
28  class AnimCurve;
29  class CustomAction;
30 
32  class MAQUINA_EXPORT Workspace : public Node
33  {
34  public:
36  Workspace(const std::shared_ptr<Impl>& impl)
37  : Node{ impl }
38  {}
39  };
40 
43 
46 
49 
52 
55 
57  MAQUINA_EXPORT void undo();
58 
60  MAQUINA_EXPORT void redo();
61 
64  const char* modification_name,
65  const gsl::span<const float>& interactive_frames = {}
66  );
68  MAQUINA_EXPORT void modify_curve_begin(const char* modification_name);
69 
71 
73 
75  MAQUINA_EXPORT void add_modify_action(const std::shared_ptr<maquina::CustomAction>& custom_action);
76 
78 
79  MAQUINA_EXPORT bool delete_animation_graph(Node& node_to_delete);
80 
83 
85  MAQUINA_EXPORT void set_current_frame(float frame);
86 
89 
92 
95  const std::vector<Plug>& channels,
96  Node& layer
97  );
98 
101  const std::vector<Plug>& channels,
102  Node& layer
103  );
104 
106 
109  Node& layer
110  );
111 
113 
116  Plug& plug,
117  const Value& value,
118  float frame,
119  bool create_curve,
120  bool layer_value=false
121  );
122 
124 
126  const Plug& plug
127  );
128 
130 
132  const Plug& plug,
133  Node& layer
134  );
135 
137 
138  MAQUINA_EXPORT std::vector<Node> in_animated_layers(
139  const Plug& plug,
140  bool skip_disabled=true
141  );
142 
145  const Plug& plug
146  );
147 
149 
151  const Plug& plug
152  );
153 
155 
157  const Plug& plug
158  );
159 
161 
163  const Plug& plug,
164  Node& layer
165  );
166 
168 
173  const Plug& plug,
174  const Node& layer,
175  float frame
176  );
177 
179 
181  Plug& animated_plug
182  );
183 
185 
187  Plug& animated_plug
188  );
189 
192  Plug& plug
193  );
194 
197  std::vector<Plug> channels,
198  bool all_layers=false
199  );
200 
202 
205  Plug& plug
206  );
207 
209 
211  Node& constraint,
212  Node& node
213  );
214 
216  /* A key will be added on all controllers already keyed in the layer */
218  Node& layer,
219  float frame,
220  bool default_value=false
221  );
222 
224  MAQUINA_EXPORT std::vector<Node> selection();
225 
227  MAQUINA_EXPORT std::vector<std::shared_ptr<NodeDelegate>> delegate_selection();
228 
230  MAQUINA_EXPORT std::vector<std::string> selection_paths();
231 
233  MAQUINA_EXPORT std::vector<std::shared_ptr<NodeDelegate>> tool_selection();
234 
236  enum class SelectionMode
237  {
238  Replace,
239  Add,
240  Remove,
241  Invert
242  };
243 
245  MAQUINA_EXPORT void select(
246  const std::vector<Node>& nodes,
248  );
249 
252  const std::vector<std::string>& paths,
254  );
255 
257  /* The return value is a list a channel full name */
258  MAQUINA_EXPORT std::unordered_set<std::string> selected_keys_channels(Node& anim_layer);
259 
261  /* The return value is a LayerKeys user data
262  */
264  Node& anim_layer
265  );
266 
268  enum class PasteMode
269  {
270  Clear,
271  Merge,
272  Replace,
273  Insert
274  };
275 
277  /* This function is looking for the best match in the active selection that leads to the closest channel.
278  * A Channel is defined as DOCUMENT/ASSET.CTRL_SIDE_CHANNEL, comparison of two channels will give a matching score.
279  * With a score given to each channels of the active selection compare to a channel to paste, the highest score will be the targeted one
280  * The overall highest score is the only one that is returned
281  * Return value is a list of matching channels
282  */
283  MAQUINA_EXPORT std::vector< std::pair<std::string, std::string> > match_channels(
284  const Value& to_match
285  );
286 
288  /* This function is looking for the best match in the selected channels that leads to the closest channel.
289  * A Channel is defined as DOCUMENT/ASSET.CTRL_SIDE_CHANNEL, comparison of two channels will give a matching score.
290  * With a score given to each channels in the selected channels compare to a channel to paste, the highest score will be the targeted one
291  * The overall highest score is the only one that is returned
292  * Return value is a list of matching channels
293  */
294  MAQUINA_EXPORT std::vector< std::pair<std::string, std::string> > match_to_channels(
295  const std::unordered_set<std::string>& channels_to_match,
296  const std::unordered_set<std::string>& selected_channels
297  );
298 
299  enum class PasteType
300  {
301  Null,
302  Soft,
303  Hard
304  };
305 
308  const Value& to_paste,
309  const std::vector< std::pair<std::string, std::string> >& matched_channels,
310  Node& dest_layer
311  );
312 
314 
319  const Value& to_paste,
320  const std::vector< std::pair<std::string, std::string> >& matched_channels, // Matching channels
321  Node& dest_layer,
322  float frame_in,
323  float frame_out,
324  float to_frame,
325  PasteMode mode = PasteMode::Merge,
326  PasteType type = PasteType::Hard
327  );
328 
330 
335  Node& anim_curve_node,
336  const AnimCurve& curve,
337  float frame_in,
338  float frame_out,
339  float to_frame,
341  );
342 
345  Node& anim_layer,
346  bool normalize=true
347  );
348 
351  Plug& plug,
352  const float frame
353  );
354 
356  MAQUINA_EXPORT void transform_keys(Node& anim_layer);
357  MAQUINA_EXPORT void transform_curve_keys(const Plug& plug, std::unordered_map<float, float>& original_to_transformed_keys);
358 
359  MAQUINA_EXPORT int insert_key(const Plug& plug, float t, float v);
360 
362  MAQUINA_EXPORT void time_warp_keys(Node& anim_layer);
363 
366  Node& layer,
367  int dest_id
368  );
369 
372  Node& parent,
373  const std::vector<Node>& layers
374  );
375 
378  Node& layer_group
379  );
380 
382  Node& layer
383  );
384 
385  // Extends the layers vector with the layer group children of type layer_type
387  Node& layer_group, //< The layer group
388  std::vector<Node>& layers, //< The layers vector to be completed
389  const char* layer_type, //< The type of layer we are looking for
390  bool recursive = false //< Go recursively in layer group children
391  );
392 
394  enum class FlattenMode
395  {
396  In_Dest_Key,
397  Union_Keys,
398  All_Frames
399  };
400 
402  /* The return value is the layer that contain the flatten result */
404  Node& layer_group,
406  int all_frames_interval = 1,
407  int all_frames_offset = 0,
408  int all_frames_tangents_mode = 1
409  );
410 
413  Node& layer,
414  Node& dest_layer,
416  int all_frames_interval=1,
417  int all_frames_offset=0,
418  int all_frames_tangents_mode=1
419  );
420 
423  Node& layer,
424  int interval = 1,
425  int offset = 0,
426  int tangents_mode = 1
427  );
428 
431  Node& curve,
432  const Plug& value_plug,
433  int interval = 1,
434  int offset = 0,
435  int tangents_mode = 1
436  );
437 
439 
444  Node& root,
445  const std::wstring& filepath,
446  const std::string& reference_root_name = ""
447  );
448 
450 
455  Node& root,
456  const std::wstring& filepath,
457  const std::string& root_name = ""
458  );
459 
461 
463  const std::vector<std::string>& channels,
464  float frame
465  );
466 
468 
470  const Dict& from_pose,
471  const Dict& to_pose,
472  float weight
473  );
474 
476 
478  const Dict& pose,
479  const std::vector<std::string>& channels
480  );
481 
483  MAQUINA_EXPORT bool has_controller(const Plug& plug);
484 
486  /*
487  * \raise{std::runtime_error,RuntimeError} if the node has no controller.
488  */
489  MAQUINA_EXPORT Node controller(const Plug& plug);
490 
492  MAQUINA_EXPORT void init_crash_handler(const std::string& message, bool send_report);
493 
495  /*
496  * \exception std::runtime_error if the node is not an animation node.
497  */
499 
501  MAQUINA_EXPORT bool is_right(Node& asset, const std::string& name);
502 
504  MAQUINA_EXPORT bool is_left(Node& asset, const std::string& name);
505 
507  MAQUINA_EXPORT std::string asset_mirror(Node& asset, const std::string& name);
508 
510  /*
511  * \raise{std::runtime_error,RuntimeError} if unable to find node's mirror or asset is not an Asset
512  */
513  MAQUINA_EXPORT Node asset_mirror_node(Node& asset, const Node& node);
514 
516  MAQUINA_EXPORT bool asset_has_manipulator(Node& asset, const std::string& manipulator_name);
517 
519  /*
520  * \raise{std::runtime_error,RuntimeError} if unable to find or node is not an asset
521  */
522  MAQUINA_EXPORT Node asset_manipulator(Node& asset, const std::string& manipulator_name);
523 
525  MAQUINA_EXPORT bool asset_has_child(Node& asset, const std::string& name);
527  /*
528  * \raise{std::runtime_error,RuntimeError} if unable to find or node is not an asset
529  */
530  MAQUINA_EXPORT Node asset_child(Node& asset, const std::string& name);
531 
533  MAQUINA_EXPORT bool asset_child_has_manipulator(Node& asset, const Node& child);
534 
536  /*
537  * \raise{std::runtime_error,RuntimeError} if unable to find or node is not an asset
538  */
539  MAQUINA_EXPORT Node asset_child_manipulator(Node& asset, const Node& child);
540 
542  MAQUINA_EXPORT Node manipulator_controller(Node& manipulator);
543 
545  MAQUINA_EXPORT std::vector<Node> asset_controllers(Node& asset);
546 
549 
551 
552  MAQUINA_EXPORT std::vector<std::pair<std::string, float>> end_profiling();
553 
555 
556  MAQUINA_EXPORT void load_document(const std::wstring& path);
557 
560 
562 
564 
567 
569  MAQUINA_EXPORT Node create_tool_geometry(const char* name, Node& parent);
570 
573 
576 
577  // Return an Asset's Display node
578  /*
579  * \raise{std::runtime_error,RuntimeError} if no display node is available for this asset
580  */
581  MAQUINA_EXPORT Node asset_display(const Node& asset);
582 
584  MAQUINA_EXPORT void increment_dirty_token();
585 
587 
589  MAQUINA_EXPORT Value weighted_sum(const Array& values, const std::vector<double>& weights);
590  }
MAQUINA_EXPORT void flush_observers()
Make sure all the observers have been called.
PasteType
Definition: Workspace.h:299
MAQUINA_EXPORT void set_current_frame(float frame)
set the current frame
MAQUINA_EXPORT Node manipulator_controller(Node &manipulator)
Get the controller related to this manipulator.
MAQUINA_EXPORT Node asset_child_manipulator(Node &asset, const Node &child)
Get the manipulator associated to the asset child.
MAQUINA_EXPORT void background_wait()
Wait for the baground evaluation engine.
MAQUINA_EXPORT bool is_left(Node &asset, const std::string &name)
Return true if the name is left using the asset mirroring rules.
MAQUINA_EXPORT Dict blend_poses(const Dict &from_pose, const Dict &to_pose, float weight)
Blend from pose to pose using weight factor.
MAQUINA_EXPORT bool has_animated_plug_in_layer(const Plug &plug, Node &layer)
Check if the plug has an animated plug in the layer.
MAQUINA_EXPORT bool can_be_flatten(Node &layer)
MAQUINA_EXPORT void background_start()
Start the background evaluation engine.
MAQUINA_EXPORT void move_layer(Node &layer, int dest_id)
Re-order layers.
MAQUINA_EXPORT Node active_document()
Return the active Document node.
MAQUINA_EXPORT void modify_begin(const char *modification_name, const gsl::span< const float > &interactive_frames={})
Begin a modification of the current document.
MAQUINA_EXPORT bool is_demo_mode()
Test if Rumba/Guerilla is in demo mode.
Add to the active selection.
MAQUINA_EXPORT Plug animated_plug_in_layer(const Plug &plug, Node &layer)
Return the animated plug in the specific layer.
MAQUINA_EXPORT Value weighted_sum(const Array &values, const std::vector< double > &weights)
Returns the weighted sum of the input values.
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.
MAQUINA_EXPORT Value default_rig_value(Plug &plug)
Return the default value if available.
MAQUINA_EXPORT Node load_node(Node &root, const std::wstring &filepath, const std::string &root_name="")
Load the content of a file into the project.
MAQUINA_EXPORT Plug background_progress()
Use this plug to be notified on background engine progress.
MAQUINA_EXPORT std::vector< Node > asset_controllers(Node &asset)
Get the asset controllers.
FlattenMode
Specify a way to flatten a layer into another.
Definition: Workspace.h:394
MAQUINA_EXPORT bool asset_has_child(Node &asset, const std::string &name)
Return true if the asset contain a child named name.
MAQUINA_EXPORT std::wstring active_document_filename()
Return the active document filename.
Keep both destination and origin layers key to perform the merge.
MAQUINA_EXPORT bool is_right(Node &asset, const std::string &name)
Return true if the name is right using the asset mirroring rules.
MAQUINA_EXPORT void add_modify_action(const std::shared_ptr< maquina::CustomAction > &custom_action)
Add a custom action to the current modifier.
MAQUINA_EXPORT void add_channels_to_layer(const std::vector< Plug > &channels, Node &layer)
Create the animation graph to make this channel animated in the layer.
MAQUINA_EXPORT bool has_animated_channel(Plug &animated_plug)
Check if the animated plug has an animated channel.
MAQUINA_EXPORT bool delete_animation_graph(Node &node_to_delete)
Delete properly the node animation graph.
MAQUINA_EXPORT void bake_layer(Node &layer, int interval=1, int offset=0, int tangents_mode=1)
Bake the layer.
MAQUINA_EXPORT void paste_keys_on_curve(Node &anim_curve_node, const AnimCurve &curve, float frame_in, float frame_out, float to_frame, PasteMode mode=PasteMode::Merge)
Paste the curve keys into an animation curve node.
MAQUINA_EXPORT void remove_keys(Node &anim_layer, bool normalize=true)
Remove the active key selection in a layer.
Insert the clipboard at the destination frame.
PasteMode
Specify a way to paste the clipboard.
Definition: Workspace.h:268
MAQUINA_EXPORT Node create_tool_geometry(const char *name, Node &parent)
Create a geometry node for tools, i-e, not in a document.
MAQUINA_EXPORT void time_warp_keys(Node &anim_layer)
Time warp the active key selection using the selection rubberband.
MAQUINA_EXPORT Node duplicate_layer(Node &layer)
Duplicate the layer and its animation.
MAQUINA_EXPORT bool has_target_layer(const Plug &plug)
Check if the plug has a layer that can receive the plug animation.
MAQUINA_EXPORT void redo()
Make a redo step.
MAQUINA_EXPORT std::vector< Node > in_animated_layers(const Plug &plug, bool skip_disabled=true)
Return the animation layers that are modifying this plug.
MAQUINA_EXPORT void select(const std::vector< Node > &nodes, SelectionMode mode=SelectionMode::Replace)
Update the active selection with a list of nodes according to the selection mode. ...
MAQUINA_EXPORT bool asset_has_manipulator(Node &asset, const std::string &manipulator_name)
Return true if the asset contain the manipulator.
No paste match.
MAQUINA_EXPORT void ungroup_layer(Node &layer_group)
Ungroup layer.
MAQUINA_EXPORT Plug animated_channel(Plug &animated_plug)
Return the animated channel connected to a layer.
MAQUINA_EXPORT void transform_keys(Node &anim_layer)
Transform the active key selection using the selection rubberband.
MAQUINA_EXPORT Node asset_mirror_node(Node &asset, const Node &node)
Return the mirrored node using the asset mirroring rules.
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
MAQUINA_EXPORT Dict matching_pose(const Dict &pose, const std::vector< std::string > &channels)
Match a pose to a set of channels.
MAQUINA_EXPORT bool has_controller(const Plug &plug)
Test if a controller is associated to a plug.
MAQUINA_EXPORT std::unordered_set< std::string > selected_keys_channels(Node &anim_layer)
Return the channels associated with the active key selection in a layer.
MAQUINA_EXPORT std::vector< std::string > selection_paths()
Return the paths of the active node delegate selection.
MAQUINA_EXPORT std::string asset_mirror(Node &asset, const std::string &name)
Return the mirrored name using the asset mirroring rules.
Only keep the destination layers key to perform the merge.
MAQUINA_EXPORT void select_delegate(const std::vector< std::string > &paths, SelectionMode mode=SelectionMode::Replace)
Update the active selection with a list of node paths according to the selection mode.
Soft paste match.
MAQUINA_EXPORT Node asset_display(const Node &asset)
MAQUINA_EXPORT Value animated_plug_value_in_layer(const Plug &plug, const Node &layer, float frame)
Return the animated plug value in the specific layer.
MAQUINA_EXPORT void delete_channels_animation(std::vector< Plug > channels, bool all_layers=false)
Reset the channels value in their target layer without removing the channel from the layer...
MAQUINA_EXPORT Node controller(const Plug &plug)
Return the controller associated to a plug.
MAQUINA_EXPORT PasteType is_paste_valid(const Value &to_paste, const std::vector< std::pair< std::string, std::string > > &matched_channels, Node &dest_layer)
Test if the targeted channels are open to be modified by the clipboard in a layer.
MAQUINA_EXPORT void load_document(const std::wstring &path)
Open a new Rumba/Guerilla project.
MAQUINA_EXPORT void constrain_node(Node &constraint, Node &node)
Constrain the node to the constraint.
Workspace is the type of the root node of the maquina Node tree.
Definition: Workspace.h:32
MAQUINA_EXPORT void start_profiling()
Start an interactive profiling session.
Hard paste match.
MAQUINA_EXPORT bool rig_matrix(Plug &plug)
Rig a matrix plug.
MAQUINA_EXPORT void set_animated_plug_value(Plug &plug, const Value &value, float frame, bool create_curve, bool layer_value=false)
Set a value to plug, regarding the target layer and the current plug animation.
MAQUINA_EXPORT void remove_channels_from_layer(const std::vector< Plug > &channels, Node &layer)
Remove the animation graph to remove this animated channel animated from the layer.
#define MAQUINA_EXPORT
Definition: Export.h:31
MAQUINA_EXPORT std::vector< std::shared_ptr< NodeDelegate > > tool_selection()
Return the active tool delegate selection.
A node plug.
Definition: Plug.h:52
MAQUINA_EXPORT void undo_blend(float undo_blend)
Set the undo blend factor of the last modification.
Invert the active selection.
MAQUINA_EXPORT void group_child_layers(Node &layer_group, std::vector< Node > &layers, const char *layer_type, bool recursive=false)
MAQUINA_EXPORT void paste_keys(const Value &to_paste, const std::vector< std::pair< std::string, std::string > > &matched_channels, Node &dest_layer, float frame_in, float frame_out, float to_frame, PasteMode mode=PasteMode::Merge, PasteType type=PasteType::Hard)
Paste values onto matching channels in a targeted layer.
SelectionMode
Specify a way to alter the active selection.
Definition: Workspace.h:236
MAQUINA_EXPORT void undo()
Make a undo step.
Replace the active selection.
MAQUINA_EXPORT Value copy_keys(Node &anim_layer)
Return a copy of the active key selection in a layer.
MAQUINA_EXPORT float current_frame()
Shortcut for the active document current frame.
MAQUINA_EXPORT std::vector< std::pair< std::string, float > > end_profiling()
Stop the interactive profiling session.
Remove from the active selection.
MAQUINA_EXPORT bool asset_child_has_manipulator(Node &asset, const Node &child)
Return true if the asset child has a manipulator.
MAQUINA_EXPORT Plug animated_plug(const Plug &plug)
Return the animated plug, regarding the current layer.
MAQUINA_EXPORT Dict extract_pose(const std::vector< std::string > &channels, float frame)
Extract a pose from a selection of plugs.
MAQUINA_EXPORT std::vector< Node > selection()
Return the active selection.
MAQUINA_EXPORT Node target_layer(const Plug &plug)
Return the layer receiving the plug animation.
MAQUINA_EXPORT std::vector< std::pair< std::string, std::string > > match_channels(const Value &to_match)
Return the best match between the channels to be pasted and the active selection. ...
MAQUINA_EXPORT Node flatten_group(Node &layer_group, FlattenMode mode=FlattenMode::Union_Keys, int all_frames_interval=1, int all_frames_offset=0, int all_frames_tangents_mode=1)
Flatten a group layer.
MAQUINA_EXPORT Node asset_child(Node &asset, const std::string &name)
Get the first child node named name of this asset.
MAQUINA_EXPORT void reparent_layers(Node &parent, const std::vector< Node > &layers)
Move layers.
MAQUINA_EXPORT void modify_curve_begin(const char *modification_name)
Begin a modification of the current document.
MAQUINA_EXPORT Node asset_manipulator(Node &asset, const std::string &manipulator_name)
Get the manipulator with the name manipulator name from this asset.
MAQUINA_EXPORT std::vector< std::shared_ptr< NodeDelegate > > delegate_selection()
Return the active node delegate selection.
Create a key at all frame to bake the whole animation of two layers into a single layer...
MAQUINA_EXPORT bool has_active_document()
Return true if there is an active Document node.
MAQUINA_EXPORT std::vector< std::pair< std::string, std::string > > match_to_channels(const std::unordered_set< std::string > &channels_to_match, const std::unordered_set< std::string > &selected_channels)
Return the best match between the channels to be pasted and the active selection. ...
MAQUINA_EXPORT bool modify_end()
End a modification of the current document.
MAQUINA_EXPORT void transform_curve_keys(const Plug &plug, std::unordered_map< float, float > &original_to_transformed_keys)
MAQUINA_EXPORT Workspace workspace()
Return the workspace node.
MAQUINA_EXPORT Plug animation_node_channel_plug(Node &node)
Get the channel plug (input of the rig) from an animation node (like an AnimCurveFloat node) ...
MAQUINA_EXPORT void bake_curve(Node &curve, const Plug &value_plug, int interval=1, int offset=0, int tangents_mode=1)
Bake curve.
MAQUINA_EXPORT void flatten_layer(Node &layer, Node &dest_layer, FlattenMode mode=FlattenMode::Union_Keys, int all_frames_interval=1, int all_frames_offset=0, int all_frames_tangents_mode=1)
Flatten a layer into the previous one.
Clear destination before paste.
MAQUINA_EXPORT bool has_animated_plug(const Plug &plug)
Check if the plug has an animated plug.
Merge the clipboard with the destination.
MAQUINA_EXPORT void init_crash_handler(const std::string &message, bool send_report)
Init the crash handler with the message to attach to the crash reports.
MAQUINA_EXPORT bool can_undo_blend()
Check if it&#39;s possible to undo blend.
MAQUINA_EXPORT int insert_key(const Plug &plug, float t, float v)
MAQUINA_EXPORT void key_layer(Node &layer, float frame, bool default_value=false)
Add a key frame on a layer.
MAQUINA_EXPORT void remove_key(Plug &plug, const float frame)
Remove the key at frame in the active layer.
MAQUINA_EXPORT void new_document()
Close the current document and create a new one.
Base class of all Rumba nodes.
Definition: Node.h:36