3e45ce26477e4d53f161cfa94567f09a9a835473
[synfig.git] /
1 /* === S Y N F I G ========================================================= */
2 /*!     \file action_param.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "action_param.h"
33 #include "action.h"
34 #include "canvasinterface.h"
35
36 #include "general.h"
37
38 #endif
39
40 using namespace std;
41 using namespace etl;
42 using namespace synfig;
43 using namespace synfigapp;
44 using namespace Action;
45
46 /* === P R O C E D U R E S ================================================= */
47
48 bool
49 Action::candidate_check(const ParamVocab& param_vocab, const ParamList& param_list)
50 {
51         ParamVocab::const_iterator iter;
52
53         for(iter=param_vocab.begin();iter!=param_vocab.end();++iter)
54         {
55                 int n(param_list.count(iter->get_name()));
56
57 //              if(n && !iter->get_mutual_exclusion().empty() && param_list.count(iter->get_mutual_exclusion()))
58 //                      return false;
59
60                 if(!n && !iter->get_mutual_exclusion().empty() && param_list.count(iter->get_mutual_exclusion()))
61                         continue;
62
63                 if(iter->get_user_supplied() || iter->get_optional())
64                         continue;
65
66                 if(n==0)
67                         return false;
68                 if(n==1 && iter->get_requires_multiple())
69                         return false;
70                 if(n>1 && !iter->get_supports_multiple())
71                         return false;
72
73                 if(iter->get_type()!=param_list.find(iter->get_name())->second.get_type())
74                         return false;
75         }
76         return true;
77 }
78
79 /* === S T A T I C S ======================================================= */
80
81 struct _ParamCounter
82 {
83         static int counter;
84         ~_ParamCounter()
85         {
86                 if(counter)
87                         synfig::error("%d action params not yet deleted!",counter);
88         }
89 } _param_counter;
90
91 int _ParamCounter::counter(0);
92
93 /* === M E T H O D S ======================================================= */
94
95 Param::Param(const Param &rhs):
96         type_(rhs.type_)
97 {
98         _ParamCounter::counter++;
99         switch(type_)
100         {
101         case TYPE_ACTIVEPOINT:
102                 data.activepoint.construct();
103                 data.activepoint.get()=rhs.data.activepoint.get();
104                 break;
105         case TYPE_WAYPOINT:
106                 data.waypoint.construct();
107                 data.waypoint.get()=rhs.data.waypoint.get();
108                 break;
109         case TYPE_WAYPOINTMODEL:
110                 data.waypoint_model.construct();
111                 data.waypoint_model.get()=rhs.data.waypoint_model.get();
112                 break;
113         case TYPE_KEYFRAME:
114                 data.keyframe.construct();
115                 data.keyframe.get()=rhs.data.keyframe.get();
116                 break;
117         case TYPE_CANVAS:
118                 data.canvas.construct();
119                 data.canvas.get()=rhs.data.canvas.get();
120                 break;
121         case TYPE_CANVASINTERFACE:
122                 data.canvas_interface.construct();
123                 data.canvas_interface.get()=rhs.data.canvas_interface.get();
124                 break;
125         case TYPE_LAYER:
126                 data.layer.construct();
127                 data.layer.get()=rhs.data.layer.get();
128                 break;
129         case TYPE_VALUENODE:
130                 data.value_node.construct();
131                 data.value_node.get()=rhs.data.value_node.get();
132                 break;
133         case TYPE_VALUEDESC:
134                 data.value_desc.construct();
135                 data.value_desc.get()=rhs.data.value_desc.get();
136                 break;
137         case TYPE_VALUE:
138                 data.value.construct();
139                 data.value.get()=rhs.data.value.get();
140                 break;
141         case TYPE_STRING:
142                 data.string.construct();
143                 data.string.get()=rhs.data.string.get();
144                 break;
145         case TYPE_RENDDESC:
146                 data.rend_desc.construct();
147                 data.rend_desc.get()=rhs.data.rend_desc.get();
148                 break;
149         case TYPE_TIME:
150                 data.time.construct();
151                 data.time.get()=rhs.data.time.get();
152                 break;
153
154         case TYPE_INTEGER:
155                 data.integer=rhs.data.integer;
156                 break;
157         case TYPE_EDITMODE:
158                 data.edit_mode=rhs.data.edit_mode;
159                 break;
160         case TYPE_REAL:
161                 data.real=rhs.data.real;
162                 break;
163         case TYPE_BOOL:
164                 data.b=rhs.data.b;
165                 break;
166
167         case TYPE_NIL:
168                 break;
169
170         default:
171                 assert(0);
172                 break;
173         }
174 }
175
176 Param::Param(const etl::handle<synfigapp::CanvasInterface>& x):
177
178         type_(TYPE_CANVASINTERFACE)
179 {
180         _ParamCounter::counter++;
181         data.canvas_interface.construct();
182         data.canvas_interface.get()=x;
183 }
184
185 /*
186 Param::Param(synfigapp::CanvasInterface* x):
187
188         type_(TYPE_CANVASINTERFACE)
189 {
190         _ParamCounter::counter++;
191         data.canvas_interface.construct();
192         data.canvas_interface=x;
193 }
194 */
195
196 Param::Param(const etl::loose_handle<synfigapp::CanvasInterface>& x):
197
198         type_(TYPE_CANVASINTERFACE)
199 {
200         _ParamCounter::counter++;
201         data.canvas_interface.construct();
202         data.canvas_interface.get()=x;
203 }
204
205 Param::Param(const synfig::Canvas::Handle& x):
206         type_(TYPE_CANVAS)
207 {
208         _ParamCounter::counter++;
209         data.canvas.construct();
210         data.canvas.get()=x;
211 }
212
213 Param::Param(const synfig::Canvas::LooseHandle& x):
214         type_(TYPE_CANVAS)
215 {
216         _ParamCounter::counter++;
217         data.canvas.construct();
218         data.canvas.get()=x;
219 }
220
221 Param::Param(const synfig::Layer::Handle& x):
222
223         type_(TYPE_LAYER)
224 {
225         _ParamCounter::counter++;
226         data.layer.construct();
227         data.layer.get()=x;
228 }
229
230 Param::Param(const synfig::Layer::LooseHandle& x):
231
232         type_(TYPE_LAYER)
233 {
234         _ParamCounter::counter++;
235         data.layer.construct();
236         data.layer.get()=x;
237 }
238
239 Param::Param(const synfig::ValueNode::Handle& x):
240
241         type_(TYPE_VALUENODE)
242 {
243         _ParamCounter::counter++;
244         data.value_node.construct();
245         data.value_node.get()=x;
246 }
247
248 Param::Param(const synfig::ValueNode::LooseHandle& x):
249
250         type_(TYPE_VALUENODE)
251 {
252         _ParamCounter::counter++;
253         data.value_node.construct();
254         data.value_node.get()=x;
255 }
256
257 Param::Param(const synfig::ValueBase& x):
258
259         type_(TYPE_VALUE)
260 {
261         _ParamCounter::counter++;
262         data.value.construct();
263         data.value.get()=x;
264 }
265
266 Param::Param(const synfig::RendDesc& x):
267         type_(TYPE_RENDDESC)
268 {
269         _ParamCounter::counter++;
270         data.rend_desc.construct();
271         data.rend_desc.get()=x;
272 }
273
274 Param::Param(const synfig::Time& x):
275         type_(TYPE_TIME)
276 {
277         _ParamCounter::counter++;
278         data.time.construct();
279         data.time.get()=x;
280 }
281
282 Param::Param(const synfig::Activepoint& x):
283
284         type_(TYPE_ACTIVEPOINT)
285 {
286         _ParamCounter::counter++;
287         data.activepoint.construct();
288         data.activepoint.get()=x;
289 }
290
291 Param::Param(const synfig::Waypoint& x):
292         type_(TYPE_WAYPOINT)
293 {
294         _ParamCounter::counter++;
295         data.waypoint.construct();
296         data.waypoint.get()=x;
297 }
298
299 Param::Param(const synfig::Waypoint::Model& x):
300         type_(TYPE_WAYPOINTMODEL)
301 {
302         _ParamCounter::counter++;
303         data.waypoint_model.construct();
304         data.waypoint_model.get()=x;
305 }
306
307 Param::Param(const synfig::String& x):
308         type_(TYPE_STRING)
309 {
310         _ParamCounter::counter++;
311         data.string.construct();
312         data.string.get()=x;
313 }
314
315 Param::Param(const char * x):
316         type_(TYPE_STRING)
317 {
318         _ParamCounter::counter++;
319         data.string.construct();
320         data.string.get()=x;
321 }
322
323 Param::Param(const synfig::Keyframe& x):
324
325         type_(TYPE_KEYFRAME)
326 {
327         _ParamCounter::counter++;
328         data.keyframe.construct();
329         data.keyframe.get()=x;
330 }
331
332 Param::Param(const synfigapp::ValueDesc& x):
333
334         type_(TYPE_VALUEDESC)
335 {
336         _ParamCounter::counter++;
337         data.value_desc.construct();
338         data.value_desc.get()=x;
339 }
340
341 Param::Param(const int& x):
342         type_(TYPE_INTEGER)
343 {
344         _ParamCounter::counter++;
345         data.integer=x;
346 }
347
348 Param::Param(const EditMode& x):
349         type_(TYPE_EDITMODE)
350 {
351         _ParamCounter::counter++;
352         data.edit_mode=x;
353 }
354
355 Param::Param(const synfig::Real& x):
356
357         type_(TYPE_REAL)
358 {
359         _ParamCounter::counter++;
360         data.real=x;
361 }
362
363 Param::Param(const bool& x):
364
365         type_(TYPE_BOOL)
366 {
367         _ParamCounter::counter++;
368         data.b=x;
369 }
370
371 Param::~Param()
372 {
373         clear();
374         _ParamCounter::counter--;
375 }
376
377 Param&
378 Param::operator=(const Param& rhs)
379 {
380         clear();
381         type_=rhs.type_;
382
383         switch(type_)
384         {
385         case TYPE_ACTIVEPOINT:
386                 data.activepoint.construct();
387                 data.activepoint.get()=rhs.data.activepoint.get();
388                 break;
389         case TYPE_WAYPOINT:
390                 data.waypoint.construct();
391                 data.waypoint.get()=rhs.data.waypoint.get();
392                 break;
393         case TYPE_WAYPOINTMODEL:
394                 data.waypoint_model.construct();
395                 data.waypoint_model.get()=rhs.data.waypoint_model.get();
396                 break;
397         case TYPE_KEYFRAME:
398                 data.keyframe.construct();
399                 data.keyframe.get()=rhs.data.keyframe.get();
400                 break;
401         case TYPE_CANVAS:
402                 data.canvas.construct();
403                 data.canvas.get()=rhs.data.canvas.get();
404                 break;
405         case TYPE_CANVASINTERFACE:
406                 data.canvas_interface.construct();
407                 data.canvas_interface.get()=rhs.data.canvas_interface.get();
408                 break;
409         case TYPE_TIME:
410                 data.time.construct();
411                 data.time.get()=rhs.data.time.get();
412                 break;
413         case TYPE_LAYER:
414                 data.layer.construct();
415                 data.layer.get()=rhs.data.layer.get();
416                 break;
417         case TYPE_VALUENODE:
418                 data.value_node.construct();
419                 data.value_node.get()=rhs.data.value_node.get();
420                 break;
421         case TYPE_VALUEDESC:
422                 data.value_desc.construct();
423                 data.value_desc.get()=rhs.data.value_desc.get();
424                 break;
425         case TYPE_VALUE:
426                 data.value.construct();
427                 data.value.get()=rhs.data.value.get();
428                 break;
429         case TYPE_RENDDESC:
430                 data.rend_desc.construct();
431                 data.rend_desc.get()=rhs.data.rend_desc.get();
432                 break;
433         case TYPE_STRING:
434                 data.string.construct();
435                 data.string.get()=rhs.data.string.get();
436                 break;
437
438         case TYPE_INTEGER:
439                 data.integer=rhs.data.integer;
440                 break;
441         case TYPE_EDITMODE:
442                 data.integer=rhs.data.integer;
443                 break;
444         case TYPE_REAL:
445                 data.real=rhs.data.real;
446                 break;
447         case TYPE_BOOL:
448                 data.b=rhs.data.b;
449                 break;
450
451         case TYPE_NIL:
452                 break;
453
454         default:
455                 assert(0);
456                 break;
457         }
458         return *this;
459 }
460
461 void
462 Param::clear()
463 {
464         switch(type_)
465         {
466         case TYPE_ACTIVEPOINT:
467                 data.activepoint.destruct();
468                 break;
469         case TYPE_WAYPOINT:
470                 data.waypoint.destruct();
471                 break;
472         case TYPE_WAYPOINTMODEL:
473                 data.waypoint_model.destruct();
474                 break;
475         case TYPE_KEYFRAME:
476                 data.keyframe.destruct();
477                 break;
478         case TYPE_CANVAS:
479                 data.canvas.destruct();
480                 break;
481         case TYPE_CANVASINTERFACE:
482                 data.canvas_interface.destruct();
483                 break;
484         case TYPE_LAYER:
485                 data.layer.destruct();
486                 break;
487         case TYPE_TIME:
488                 data.time.destruct();
489                 break;
490         case TYPE_VALUENODE:
491                 data.value_node.destruct();
492                 break;
493         case TYPE_VALUEDESC:
494                 data.value_desc.destruct();
495                 break;
496         case TYPE_VALUE:
497                 data.value.destruct();
498                 break;
499         case TYPE_RENDDESC:
500                 data.rend_desc.destruct();
501                 break;
502         case TYPE_STRING:
503                 data.string.destruct();
504                 break;
505
506         case TYPE_NIL:
507         case TYPE_EDITMODE:
508         case TYPE_INTEGER:
509         case TYPE_REAL:
510         case TYPE_BOOL:
511                 break;
512
513         default:
514                 assert(0);
515                 break;
516         }
517         type_=TYPE_NIL;
518 }