synfig-studio  1.0.3
action_param.h
Go to the documentation of this file.
1 /* === S Y N F I G ========================================================= */
22 /* ========================================================================= */
23 
24 /* === S T A R T =========================================================== */
25 
26 #ifndef __SYNFIG_APP_ACTION_PARAM_H
27 #define __SYNFIG_APP_ACTION_PARAM_H
28 
29 /* === H E A D E R S ======================================================= */
30 
31 #include <synfig/string.h>
32 #include <synfig/canvas.h>
33 #include <ETL/handle>
34 #include <ETL/stringf>
35 #include <ETL/trivial>
36 
37 #include <map>
38 #include <list>
39 
40 #include <synfig/layer.h>
41 #include <synfig/canvas.h>
42 #include <synfig/valuenode.h>
43 #include <synfigapp/value_desc.h>
44 #include <synfig/value.h>
45 #include <synfig/activepoint.h>
46 #include <synfig/valuenodes/valuenode_animated.h>
47 #include <synfig/string.h>
48 #include <synfig/keyframe.h>
49 #include <synfig/waypoint.h>
50 
51 #include "editmode.h"
52 
53 /* === M A C R O S ========================================================= */
54 
55 /* === T Y P E D E F S ===================================================== */
56 
57 /* === C L A S S E S & S T R U C T S ======================================= */
58 
59 namespace synfig {
60 class ProgressCallback;
61 class Canvas;
62 class RendDesc;
63 }; // END of namespace synfig
64 
65 namespace synfigapp {
66 
67 class CanvasInterface;
68 
69 namespace Action {
70 
72 class Param
73 {
74 public:
75  enum Type
76  {
77  TYPE_NIL, // 0
89  TYPE_VALUE, // 12
96 
97  TYPE_END // 19
98  };
99 private:
100  Type type_;
101 
102  union
103  {
104  etl::trivial<synfig::Canvas::LooseHandle> canvas;
105  etl::trivial<synfig::Layer::LooseHandle> layer;
106  etl::trivial<synfig::ValueNode::LooseHandle> value_node;
107  etl::trivial<synfig::ValueBase> value;
108  etl::trivial<synfig::Activepoint> activepoint;
109  etl::trivial<synfig::ValueNode_Animated::Waypoint> waypoint;
110  etl::trivial<synfig::ValueNode_Animated::Waypoint::Model> waypoint_model;
111  etl::trivial<synfig::String> string;
112  etl::trivial<synfig::Keyframe> keyframe;
113  etl::trivial<synfig::Time> time;
114  etl::trivial<synfigapp::ValueDesc> value_desc;
115  etl::trivial<etl::loose_handle<synfigapp::CanvasInterface> > canvas_interface;
116  etl::trivial<synfig::RendDesc> rend_desc;
117  int integer;
118  synfig::Real real;
119  bool b;
121  synfig::Interpolation interpolation;
122 
123  } data;
124 public:
125 
126  Param():type_(TYPE_NIL) { }
127  Param(const Param &x);
128  Param(const etl::handle<synfigapp::CanvasInterface>& x);
129  Param(const etl::loose_handle<synfigapp::CanvasInterface>& x);
130 // Param(synfigapp::CanvasInterface* x);
131  Param(const synfig::Canvas::Handle& x);
132  Param(const synfig::Canvas::LooseHandle& x);
133  Param(const synfig::Layer::Handle& x);
134  Param(const synfig::Layer::LooseHandle& x);
136  Param(const synfig::ValueNode::LooseHandle& x);
137  Param(const synfig::Activepoint& x);
138  Param(const synfig::Waypoint& x);
139  Param(const synfig::Waypoint::Model& x);
140  Param(const synfig::String& x);
141  Param(const synfig::RendDesc& x);
142  Param(const char * x);
143  Param(const synfig::Keyframe& x);
144  Param(const synfigapp::ValueDesc& x);
145  Param(const int& x);
146  Param(const EditMode& x);
147  Param(const synfig::Real& x);
148  Param(const synfig::Time& x);
149  Param(const bool& x);
150  Param(const synfig::ValueBase& x);
151  Param(const synfig::Interpolation& x);
152 
153  ~Param();
154 
155  Param& operator=(const Param& rhs);
156 
157  void clear();
158 
159  const synfig::Canvas::LooseHandle& get_canvas()const { assert(type_==TYPE_CANVAS); return data.canvas.get(); }
160  const etl::loose_handle<synfigapp::CanvasInterface>& get_canvas_interface()const { assert(type_==TYPE_CANVASINTERFACE); return data.canvas_interface.get(); }
161  const synfig::Layer::LooseHandle& get_layer()const { assert(type_==TYPE_LAYER); return data.layer.get(); }
162  const synfig::ValueNode::LooseHandle& get_value_node()const { assert(type_==TYPE_VALUENODE); return data.value_node.get(); }
163  const synfig::ValueBase& get_value()const { assert(type_==TYPE_VALUE); return data.value.get(); }
164  const synfig::Activepoint& get_activepoint()const { assert(type_==TYPE_ACTIVEPOINT); return data.activepoint.get(); }
165  const synfig::Waypoint& get_waypoint()const { assert(type_==TYPE_WAYPOINT); return data.waypoint.get(); }
166  const synfig::Waypoint::Model& get_waypoint_model()const { assert(type_==TYPE_WAYPOINTMODEL); return data.waypoint_model.get(); }
167  const synfig::String& get_string()const { assert(type_==TYPE_STRING); return data.string.get(); }
168  const synfig::Keyframe& get_keyframe()const { assert(type_==TYPE_KEYFRAME); return data.keyframe.get(); }
169  const synfigapp::ValueDesc& get_value_desc()const { assert(type_==TYPE_VALUEDESC); return data.value_desc.get(); }
170  const synfig::Real& get_real()const { assert(type_==TYPE_REAL); return data.real; }
171  const synfig::Time& get_time()const { assert(type_==TYPE_TIME); return data.time.get(); }
172  const synfig::RendDesc& get_rend_desc()const { assert(type_==TYPE_RENDDESC); return data.rend_desc.get(); }
173  int get_integer()const { assert(type_==TYPE_INTEGER); return data.integer; }
174  EditMode get_edit_mode()const { assert(type_==TYPE_EDITMODE); return data.edit_mode; }
175  bool get_bool()const { assert(type_==TYPE_BOOL); return data.b; }
176  const synfig::Interpolation& get_interpolation()const { assert(type_==TYPE_INTERPOLATION); return data.interpolation; }
177 
178 
179  const Type& get_type()const { return type_; }
180 }; // END of class Param
181 
182 class ParamList : public std::multimap<synfig::String,Param>
183 {
184 public:
185  ParamList& add(const synfig::String& name, const Param &x) { insert(std::pair<synfig::String,Param>(name,x)); return *this; }
186  ParamList& add(const ParamList& x) { insert(x.begin(),x.end()); return *this; }
187  ParamList& remove_all(const synfig::String& name) { erase(name); return *this; }
188 }; // END of class ParamList
189 
191 {
192 private:
193  synfig::String name_;
194  synfig::String local_name_;
195  synfig::String desc_;
196  synfig::String mutual_exclusion_;
197  Param::Type type_;
198  bool user_supplied_;
199  bool supports_multiple_;
200  bool requires_multiple_;
201  bool optional_;
202  bool value_provided_;
203 
204 public:
205  ParamDesc(const synfig::String &name, Param::Type type):
206  name_(name),
207  local_name_(name),
208  type_(type),
209  user_supplied_(false),
210  supports_multiple_(false),
211  requires_multiple_(false),
212  optional_(false),
213  value_provided_(false)
214  { }
215 
216  const synfig::String& get_name()const { return name_; }
217  const synfig::String& get_desc()const { return desc_; }
218  const synfig::String& get_mutual_exclusion()const { return mutual_exclusion_; }
219  const synfig::String& get_local_name()const { return local_name_; }
220  const Param::Type& get_type()const { return type_; }
221  bool get_user_supplied()const { return user_supplied_; }
222  bool get_supports_multiple()const { return supports_multiple_||requires_multiple_; }
223  bool get_requires_multiple()const { return requires_multiple_; }
224  bool get_optional()const { return optional_; }
225  bool get_value_provided()const { return value_provided_; }
226 
227  ParamDesc& set_local_name(const synfig::String& x) { local_name_=x; return *this; }
228  ParamDesc& set_desc(const synfig::String& x) { desc_=x; return *this; }
229  ParamDesc& set_mutual_exclusion(const synfig::String& x) { mutual_exclusion_=x; return *this; }
230  ParamDesc& set_user_supplied(bool x=true) { user_supplied_=x; return *this; }
231  ParamDesc& set_supports_multiple(bool x=true) { supports_multiple_=x; return *this; }
232  ParamDesc& set_requires_multiple(bool x=true) { requires_multiple_=x; if(x)supports_multiple_=true; return *this; }
233  ParamDesc& set_optional(bool x=true) { optional_=x; return *this; }
234  ParamDesc& set_value_provided(bool x=true) { value_provided_=x; return *this; }
235 }; // END of class ParamDesc
236 
237 class ParamVocab : public std::list< ParamDesc > { };
238 
239 bool candidate_check(const ParamVocab& param_vocab, const ParamList& param_list);
240 
241 }; // END of namespace Action
242 
243 }; // END of namespace synfigapp
244 
245 /* === E N D =============================================================== */
246 
247 #endif