my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / action_param.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file action_param.h
3 **      \brief Template File
4 **
5 **      $Id: action_param.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SYNFIG_APP_ACTION_PARAM_H
25 #define __SYNFIG_APP_ACTION_PARAM_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include <synfig/string.h>
30 #include <synfig/canvas.h>
31 #include <ETL/handle>
32 #include <ETL/stringf>
33 #include <ETL/trivial>
34
35 #include <map>
36 #include <list>
37
38 #include <synfig/layer.h>
39 #include <synfig/canvas.h>
40 #include <synfig/valuenode.h>
41 #include <synfigapp/value_desc.h>
42 #include <synfig/value.h>
43 #include <synfig/activepoint.h>
44 #include <synfig/valuenode_animated.h>
45 #include <synfig/string.h>
46 #include <synfig/keyframe.h>
47 #include <synfig/waypoint.h>
48
49 #include "editmode.h"
50
51 /* === M A C R O S ========================================================= */
52
53 /* === T Y P E D E F S ===================================================== */
54
55 /* === C L A S S E S & S T R U C T S ======================================= */
56
57 namespace synfig {
58 class ProgressCallback;
59 class Canvas;
60 class RendDesc;
61 }; // END of namespace synfig
62
63 namespace synfigapp {
64
65 class CanvasInterface;
66         
67 namespace Action {      
68
69 //! Action Parameter
70 class Param
71 {
72 public:
73         enum Type
74         {
75                 TYPE_NIL,
76                 TYPE_INTEGER,
77                 TYPE_REAL,
78                 TYPE_BOOL,
79                 TYPE_ACTIVEPOINT,
80                 TYPE_WAYPOINT,
81                 TYPE_WAYPOINTMODEL,
82                 TYPE_KEYFRAME,
83                 TYPE_CANVAS,
84                 TYPE_LAYER,
85                 TYPE_VALUENODE,
86                 TYPE_VALUEDESC,
87                 TYPE_VALUE,
88                 TYPE_STRING,
89                 TYPE_TIME,
90                 TYPE_CANVASINTERFACE,
91                 TYPE_EDITMODE,
92                 TYPE_RENDDESC,
93                 
94                 TYPE_END
95         };
96 private:
97         Type type_;
98
99         union
100         {
101                 etl::trivial<synfig::Canvas::LooseHandle> canvas;
102                 etl::trivial<synfig::Layer::LooseHandle> layer;
103                 etl::trivial<synfig::ValueNode::LooseHandle> value_node;
104                 etl::trivial<synfig::ValueBase> value;
105                 etl::trivial<synfig::Activepoint> activepoint;
106                 etl::trivial<synfig::ValueNode_Animated::Waypoint> waypoint;
107                 etl::trivial<synfig::ValueNode_Animated::Waypoint::Model> waypoint_model;
108                 etl::trivial<synfig::String> string;
109                 etl::trivial<synfig::Keyframe> keyframe;
110                 etl::trivial<synfig::Time> time;
111                 etl::trivial<synfigapp::ValueDesc> value_desc;
112                 etl::trivial<etl::loose_handle<synfigapp::CanvasInterface> > canvas_interface;
113                 etl::trivial<synfig::RendDesc> rend_desc;
114                 int integer;
115                 synfig::Real real;
116                 bool b;
117                 EditMode edit_mode;
118                 
119         } data;
120 public:
121
122         Param():type_(TYPE_NIL) { }
123         Param(const Param &x);
124         Param(const etl::handle<synfigapp::CanvasInterface>& x);
125         Param(const etl::loose_handle<synfigapp::CanvasInterface>& x);
126 //      Param(synfigapp::CanvasInterface* x);
127         Param(const synfig::Canvas::Handle& x);
128         Param(const synfig::Canvas::LooseHandle& x);
129         Param(const synfig::Layer::Handle& x);
130         Param(const synfig::Layer::LooseHandle& x);
131         Param(const synfig::ValueNode::Handle& x);
132         Param(const synfig::ValueNode::LooseHandle& x);
133         Param(const synfig::Activepoint& x);
134         Param(const synfig::Waypoint& x);
135         Param(const synfig::Waypoint::Model& x);
136         Param(const synfig::String& x);
137         Param(const synfig::RendDesc& x);
138         Param(const char * x);
139         Param(const synfig::Keyframe& x);
140         Param(const synfigapp::ValueDesc& x);
141         Param(const int& x);
142         Param(const EditMode& x);
143         Param(const synfig::Real& x);
144         Param(const synfig::Time& x);
145         Param(const bool& x);
146         Param(const synfig::ValueBase& x);
147
148         ~Param();
149         
150         Param& operator=(const Param& rhs);
151         
152         void clear();
153         
154         const synfig::Canvas::LooseHandle& get_canvas()const { assert(type_==TYPE_CANVAS); return data.canvas.get(); }
155         const etl::loose_handle<synfigapp::CanvasInterface>& get_canvas_interface()const { assert(type_==TYPE_CANVASINTERFACE); return data.canvas_interface.get(); }
156         const synfig::Layer::LooseHandle& get_layer()const { assert(type_==TYPE_LAYER); return data.layer.get(); }
157         const synfig::ValueNode::LooseHandle& get_value_node()const { assert(type_==TYPE_VALUENODE); return data.value_node.get(); }
158         const synfig::ValueBase& get_value()const { assert(type_==TYPE_VALUE); return data.value.get(); }
159         const synfig::Activepoint& get_activepoint()const { assert(type_==TYPE_ACTIVEPOINT); return data.activepoint.get(); }
160         const synfig::Waypoint& get_waypoint()const { assert(type_==TYPE_WAYPOINT); return data.waypoint.get(); }
161         const synfig::Waypoint::Model& get_waypoint_model()const { assert(type_==TYPE_WAYPOINTMODEL); return data.waypoint_model.get(); }
162         const synfig::String& get_string()const { assert(type_==TYPE_STRING); return data.string.get(); }
163         const synfig::Keyframe& get_keyframe()const { assert(type_==TYPE_KEYFRAME); return data.keyframe.get(); }
164         const synfigapp::ValueDesc& get_value_desc()const { assert(type_==TYPE_VALUEDESC); return data.value_desc.get(); }
165         const synfig::Real& get_real()const { assert(type_==TYPE_REAL); return data.real; }
166         const synfig::Time& get_time()const { assert(type_==TYPE_TIME); return data.time.get(); }
167         const synfig::RendDesc& get_rend_desc()const { assert(type_==TYPE_RENDDESC); return data.rend_desc.get(); }
168         int get_integer()const { assert(type_==TYPE_INTEGER); return data.integer; }
169         EditMode get_edit_mode()const { assert(type_==TYPE_EDITMODE); return data.edit_mode; }
170         bool get_bool()const { assert(type_==TYPE_BOOL); return data.b; }
171
172
173         const Type& get_type()const { return type_; }
174 }; // END of class Param
175
176 class ParamList : public std::multimap<synfig::String,Param>
177 {
178 public:
179         ParamList& add(const synfig::String& name, const Param &x) { insert(std::pair<synfig::String,Param>(name,x)); return *this; }
180         ParamList& add(const ParamList& x) { insert(x.begin(),x.end()); return *this; }
181 }; // END of class ParamList
182
183 class ParamDesc
184 {
185 private:
186         synfig::String  name_;
187         synfig::String  local_name_;
188         synfig::String  desc_;
189         synfig::String  mutual_exclusion_;
190         Param::Type     type_;
191         bool    user_supplied_;
192         bool    supports_multiple_;
193         bool    requires_multiple_;
194         bool    optional_;
195
196 public:
197         ParamDesc(const synfig::String &name, Param::Type type):
198                 name_(name),
199                 local_name_(name),
200                 type_(type),
201                 user_supplied_(false),
202                 supports_multiple_(false),
203                 requires_multiple_(false),
204                 optional_(false)
205         { }
206         
207         const synfig::String& get_name()const { return name_; }
208         const synfig::String& get_desc()const { return desc_; }
209         const synfig::String& get_mutual_exclusion()const { return mutual_exclusion_; }
210         const synfig::String& get_local_name()const { return local_name_; }
211         const Param::Type& get_type()const { return type_; }
212         bool get_user_supplied()const { return user_supplied_; }
213         bool get_supports_multiple()const { return supports_multiple_||requires_multiple_; }
214         bool get_requires_multiple()const { return requires_multiple_; }
215         bool get_optional()const { return optional_; }
216
217         ParamDesc& set_local_name(const synfig::String& x) { local_name_=x; return *this; }
218         ParamDesc& set_desc(const synfig::String& x) { desc_=x; return *this; }
219         ParamDesc& set_mutual_exclusion(const synfig::String& x) { mutual_exclusion_=x; return *this; }
220         ParamDesc& set_user_supplied(bool x=true) { user_supplied_=x; return *this; }
221         ParamDesc& set_supports_multiple(bool x=true) { supports_multiple_=x; return *this; }
222         ParamDesc& set_requires_multiple(bool x=true) { requires_multiple_=x; if(x)supports_multiple_=true; return *this; }
223         ParamDesc& set_optional(bool x=true) { optional_=x; return *this; }
224 }; // END of class ParamDesc
225
226 class ParamVocab : public std::list< ParamDesc > { };
227
228 bool canidate_check(const ParamVocab& param_vocab, const ParamList& param_list);
229
230 }; // END of namespace Action
231
232 }; // END of namespace synfigapp
233
234 /* === E N D =============================================================== */
235
236 #endif