1 /* === S Y N F I G ========================================================= */
2 /*!	\file action_param.h
3 **	\brief Template File
4 **
5 **	$Id$
6 **
7 **	\legal
8 **	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **	Copyright (c) 2007 Chris Moore
10 **
11 **	This package is free software; you can redistribute it and/or
12 **	modify it under the terms of the GNU General Public License as
13 **	published by the Free Software Foundation; either version 2 of
14 **	the License, or (at your option) any later version.
15 **
16 **	This package is distributed in the hope that it will be useful,
17 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **	General Public License for more details.
20 **	\endlegal
21 */
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 
71 //! Action Parameter
72 class Param
73 {
74 public:
75 	enum Type
76 	{
77 		TYPE_NIL,				// 0
78 		TYPE_INTEGER,
79 		TYPE_REAL,
80 		TYPE_BOOL,
81 		TYPE_ACTIVEPOINT,		// 4
82 		TYPE_WAYPOINT,
83 		TYPE_WAYPOINTMODEL,
84 		TYPE_KEYFRAME,
85 		TYPE_CANVAS,			// 8
86 		TYPE_LAYER,
87 		TYPE_VALUENODE,
88 		TYPE_VALUEDESC,
89 		TYPE_VALUE,				// 12
90 		TYPE_STRING,
91 		TYPE_TIME,
92 		TYPE_CANVASINTERFACE,
93 		TYPE_EDITMODE,			// 16
94 		TYPE_RENDDESC,
95 		TYPE_INTERPOLATION,
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;
120 		EditMode edit_mode;
121 		synfig::Interpolation interpolation;
122 
123 	} data;
124 public:
125 
Param()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);
135 	Param(const synfig::ValueNode::Handle& 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 
get_canvas()159 	const synfig::Canvas::LooseHandle& get_canvas()const { assert(type_==TYPE_CANVAS); return data.canvas.get(); }
get_canvas_interface()160 	const etl::loose_handle<synfigapp::CanvasInterface>& get_canvas_interface()const { assert(type_==TYPE_CANVASINTERFACE); return data.canvas_interface.get(); }
get_layer()161 	const synfig::Layer::LooseHandle& get_layer()const { assert(type_==TYPE_LAYER); return data.layer.get(); }
get_value_node()162 	const synfig::ValueNode::LooseHandle& get_value_node()const { assert(type_==TYPE_VALUENODE); return data.value_node.get(); }
get_value()163 	const synfig::ValueBase& get_value()const { assert(type_==TYPE_VALUE); return data.value.get(); }
get_activepoint()164 	const synfig::Activepoint& get_activepoint()const { assert(type_==TYPE_ACTIVEPOINT); return data.activepoint.get(); }
get_waypoint()165 	const synfig::Waypoint& get_waypoint()const { assert(type_==TYPE_WAYPOINT); return data.waypoint.get(); }
get_waypoint_model()166 	const synfig::Waypoint::Model& get_waypoint_model()const { assert(type_==TYPE_WAYPOINTMODEL); return data.waypoint_model.get(); }
get_string()167 	const synfig::String& get_string()const { assert(type_==TYPE_STRING); return data.string.get(); }
get_keyframe()168 	const synfig::Keyframe& get_keyframe()const { assert(type_==TYPE_KEYFRAME); return data.keyframe.get(); }
get_value_desc()169 	const synfigapp::ValueDesc& get_value_desc()const { assert(type_==TYPE_VALUEDESC); return data.value_desc.get(); }
get_real()170 	const synfig::Real& get_real()const { assert(type_==TYPE_REAL); return data.real; }
get_time()171 	const synfig::Time& get_time()const { assert(type_==TYPE_TIME); return data.time.get(); }
get_rend_desc()172 	const synfig::RendDesc& get_rend_desc()const { assert(type_==TYPE_RENDDESC); return data.rend_desc.get(); }
get_integer()173 	int get_integer()const { assert(type_==TYPE_INTEGER); return data.integer; }
get_edit_mode()174 	EditMode get_edit_mode()const { assert(type_==TYPE_EDITMODE); return data.edit_mode; }
get_bool()175 	bool get_bool()const { assert(type_==TYPE_BOOL); return data.b; }
get_interpolation()176 	const synfig::Interpolation& get_interpolation()const { assert(type_==TYPE_INTERPOLATION); return data.interpolation; }
177 
178 
get_type()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:
add(const synfig::String & name,const Param & x)185 	ParamList& add(const synfig::String& name, const Param &x) { insert(std::pair<synfig::String,Param>(name,x)); return *this; }
add(const ParamList & x)186 	ParamList& add(const ParamList& x) { insert(x.begin(),x.end()); return *this; }
remove_all(const synfig::String & name)187 	ParamList& remove_all(const synfig::String& name) { erase(name); return *this; }
188 }; // END of class ParamList
189 
190 class ParamDesc
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:
ParamDesc(const synfig::String & name,Param::Type type)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 
get_name()216 	const synfig::String& get_name()const { return name_; }
get_desc()217 	const synfig::String& get_desc()const { return desc_; }
get_mutual_exclusion()218 	const synfig::String& get_mutual_exclusion()const { return mutual_exclusion_; }
get_local_name()219 	const synfig::String& get_local_name()const { return local_name_; }
get_type()220 	const Param::Type& get_type()const { return type_; }
get_user_supplied()221 	bool get_user_supplied()const { return user_supplied_; }
get_supports_multiple()222 	bool get_supports_multiple()const { return supports_multiple_||requires_multiple_; }
get_requires_multiple()223 	bool get_requires_multiple()const { return requires_multiple_; }
get_optional()224 	bool get_optional()const { return optional_; }
get_value_provided()225 	bool get_value_provided()const { return value_provided_; }
226 
set_local_name(const synfig::String & x)227 	ParamDesc& set_local_name(const synfig::String& x) { local_name_=x; return *this; }
set_desc(const synfig::String & x)228 	ParamDesc& set_desc(const synfig::String& x) { desc_=x; return *this; }
set_mutual_exclusion(const synfig::String & x)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
248